Documentation ¶
Overview ¶
Package ion provides all the functionality you need to interact with an ION service and manage your ION DID. To start, create a new ION resolution object using the NewResolver function. This will create a new resolution that can resolve and anchor ION DIDs. Next, create a new ION DID using the NewIONDID function. This will create a new ION DID object with a set of receiver methods that can be used to generate operations to submit to the ION service. For example: // Create a new ION resolution resolution, err := ion.NewResolver(http.DefaultClient, "https://ion.tbd.network")
if err != nil { panic(err) }
// Create a new ION DID did, createOp, err := ion.NewIONDID(Document{[]Service{Service{ID: "serviceID", Type: "serviceType"}}})
if err != nil { panic(err) }
// Submit the create operation to the ION service err = resolution.Anchor(ctx, createOp)
if err != nil { panic(err) }
// Resolve the DID result, err := resolution.Resolve(ctx, did, nil)
if err != nil { panic(err) }
Index ¶
- Constants
- func Canonicalize(data []byte) ([]byte, error)
- func CanonicalizeAny(data any) ([]byte, error)
- func Commit(key sdkcrypto.PublicKeyJWK) (reveal, commitment string, err error)
- func CreateLongFormDID(recoveryKey, updateKey jwx.PublicKeyJWK, document Document) (string, error)
- func CreateShortFormDID(suffixData any) (string, error)
- func Decode(data string) ([]byte, error)
- func Encode(data []byte) string
- func EncodeAny(data any) (string, error)
- func EncodeString(data string) string
- func Hash(data []byte) []byte
- func HashEncode(data []byte) (string, error)
- func IsLongFormDID(maybeLongFormDID string) bool
- func LongToShortFormDID(longFormDID string) (string, error)
- func Multihash(data []byte) ([]byte, error)
- func NewIONDID(doc Document) (*DID, *CreateRequest, error)
- func PatchesToDIDDocument(shortFormDID, longFormDID string, patches []Patch) (*did.Document, error)
- type AddPublicKeysAction
- type AddServicesAction
- type AnchorOperation
- type BTCSignerVerifier
- func (*BTCSignerVerifier) GetJWSHeader() map[string]any
- func (sv *BTCSignerVerifier) Sign(dataHash []byte) ([]byte, error)
- func (sv *BTCSignerVerifier) SignJWT(data any) (string, error)
- func (sv *BTCSignerVerifier) Verify(data, signature []byte) (bool, error)
- func (sv *BTCSignerVerifier) VerifyJWS(jws string) (bool, error)
- type CreateRequest
- type DID
- func (d DID) Deactivate() (*DID, *DeactivateRequest, error)
- func (d DID) GetRecoveryPrivateKey() jwx.PrivateKeyJWK
- func (d DID) GetUpdatePrivateKey() jwx.PrivateKeyJWK
- func (d DID) ID() string
- func (d DID) IsEmpty() bool
- func (d DID) LongForm() string
- func (d DID) Operation(index int) any
- func (d DID) Operations() []any
- func (d DID) Recover(doc Document) (*DID, *RecoverRequest, error)
- func (d DID) Update(stateChange StateChange) (*DID, *UpdateRequest, error)
- type DeactivateRequest
- type DeactivateSignedDataObject
- type Delta
- func (d *Delta) AddAddPublicKeysAction(patch AddPublicKeysAction)
- func (d *Delta) AddAddServicesAction(patch AddServicesAction)
- func (d *Delta) AddRemovePublicKeysAction(patch RemovePublicKeysAction)
- func (d *Delta) AddRemoveServicesAction(patch RemoveServicesAction)
- func (d *Delta) AddReplaceAction(patch ReplaceAction)
- func (d *Delta) GetPatches() []Patch
- func (d *Delta) UnmarshalJSON(data []byte) error
- type Document
- type ErrorCode
- type ION
- type InitialState
- type LocalResolver
- type Network
- type OperationKeyType
- type OperationType
- type Patch
- type PatchAction
- type PublicKey
- type RecoverRequest
- type RecoverySignedDataObject
- type RemovePublicKeysAction
- type RemoveServicesAction
- type ReplaceAction
- type Resolver
- type StateChange
- type SuffixData
- type UpdateRequest
- type UpdateSignedDataObject
Constants ¶
const (
Prefix = "did:ion"
)
Variables ¶
This section is empty.
Functions ¶
func Canonicalize ¶
Canonicalize transforms JSON according to the protocol's JSON Canonicalization Scheme https://identity.foundation/sidetree/spec/#json-canonicalization-scheme
func CanonicalizeAny ¶
CanonicalizeAny transforms JSON according to the protocol's JSON Canonicalization Scheme https://identity.foundation/sidetree/spec/#json-canonicalization-scheme
func Commit ¶
func Commit(key sdkcrypto.PublicKeyJWK) (reveal, commitment string, err error)
Commit creates a public key commitment according to the steps defined in the protocol https://identity.foundation/sidetree/spec/#public-key-commitment-scheme
func CreateLongFormDID ¶
func CreateLongFormDID(recoveryKey, updateKey jwx.PublicKeyJWK, document Document) (string, error)
CreateLongFormDID generates a long form DID URI representation from a document, recovery, and update keys, intended to be the initial state of a DID Document. The method follows the guidelines in the spec: https://identity.foundation/sidetree/spec/#long-form-did-uris
func CreateShortFormDID ¶
CreateShortFormDID follows the process on did uri composition from the spec: https://identity.foundation/sidetree/spec/#did-uri-composition, used to generate a short form DID URI, which is most frequently used in the protocol and when sharing out ION DIDs.
func EncodeString ¶
EncodeString encodes a string according to the encoding scheme of the sidetree spec
func HashEncode ¶
HashEncode hashes given data according to the protocol's hashing process https://identity.foundation/sidetree/spec/#hashing-process
func IsLongFormDID ¶
IsLongFormDID checks if a string is a long form DID URI
func LongToShortFormDID ¶
LongToShortFormDID returns the short form DID from a long form DID
func Multihash ¶
Multihash https://multiformats.io/multihash/
func NewIONDID ¶
func NewIONDID(doc Document) (*DID, *CreateRequest, error)
NewIONDID creates a new ION DID with a new recovery and update key pairs, of type secp256k1, in addition to any content passed into in the document parameter. The result is a DID object that contains the long form DID, and operations to be submitted to an anchor service.
Types ¶
type AddPublicKeysAction ¶
type AddPublicKeysAction struct { Action PatchAction `json:"action,omitempty"` PublicKeys []PublicKey `json:"publicKeys,omitempty"` }
AddPublicKeysAction https://identity.foundation/sidetree/spec/#add-public-keys
func (AddPublicKeysAction) GetAction ¶
func (a AddPublicKeysAction) GetAction() PatchAction
type AddServicesAction ¶
type AddServicesAction struct { Action PatchAction `json:"action,omitempty"` Services []did.Service `json:"services,omitempty"` }
AddServicesAction https://identity.foundation/sidetree/spec/#add-services
func (AddServicesAction) GetAction ¶
func (a AddServicesAction) GetAction() PatchAction
type AnchorOperation ¶
type AnchorOperation interface {
GetType() OperationType
}
type BTCSignerVerifier ¶
type BTCSignerVerifier struct {
// contains filtered or unexported fields
}
func NewBTCSignerVerifier ¶
func NewBTCSignerVerifier(privateKey sdkcrypto.PrivateKeyJWK) (*BTCSignerVerifier, error)
NewBTCSignerVerifier creates a new signer/verifier for signatures suited for the BTC blockchain
func (*BTCSignerVerifier) GetJWSHeader ¶
func (*BTCSignerVerifier) GetJWSHeader() map[string]any
GetJWSHeader returns the default JWS header for the BTC signer
func (*BTCSignerVerifier) Sign ¶
func (sv *BTCSignerVerifier) Sign(dataHash []byte) ([]byte, error)
Sign signs the given data according to Bitcoin's signing process
func (*BTCSignerVerifier) SignJWT ¶
func (sv *BTCSignerVerifier) SignJWT(data any) (string, error)
SignJWT signs the given data according to the protocol's JWT signing process, creating a compact JWS in a JWT
type CreateRequest ¶
type CreateRequest struct { Type OperationType `json:"type,omitempty"` SuffixData SuffixData `json:"suffixData,omitempty"` Delta Delta `json:"delta,omitempty"` }
func NewCreateRequest ¶
func NewCreateRequest(recoveryKey, updateKey jwx.PublicKeyJWK, document Document) (*CreateRequest, error)
NewCreateRequest creates a new create request https://identity.foundation/sidetree/spec/#create
func (CreateRequest) GetType ¶
func (CreateRequest) GetType() OperationType
type DID ¶
type DID struct {
// contains filtered or unexported fields
}
DID is a representation of a did:ion DID and should be used to maintain the state of an ION DID Document. It contains the DID suffix, the long form DID, the operations of the DID, and both the update and recovery private keys. All receiver methods are side effect free, and return new instances of DID with the updated state.
func (DID) Deactivate ¶
func (d DID) Deactivate() (*DID, *DeactivateRequest, error)
Deactivate creates a terminal state DID and the corresponding anchor operation to submit to the anchor service.
func (DID) GetRecoveryPrivateKey ¶
func (d DID) GetRecoveryPrivateKey() jwx.PrivateKeyJWK
func (DID) GetUpdatePrivateKey ¶
func (d DID) GetUpdatePrivateKey() jwx.PrivateKeyJWK
func (DID) Operations ¶
func (DID) Recover ¶
func (d DID) Recover(doc Document) (*DID, *RecoverRequest, error)
Recover recovers the DID object's state with a provided document object, returning a new DID object and recover operation to be submitted to an anchor service.
func (DID) Update ¶
func (d DID) Update(stateChange StateChange) (*DID, *UpdateRequest, error)
Update updates the DID object's state with a provided state change object. The result is a new DID object with the update key pair and an update operation to be submitted to an anchor service.
type DeactivateRequest ¶
type DeactivateRequest struct { Type OperationType `json:"type,omitempty"` DIDSuffix string `json:"didSuffix,omitempty"` RevealValue string `json:"revealValue,omitempty"` SignedData string `json:"signedData,omitempty"` }
func NewDeactivateRequest ¶
func NewDeactivateRequest(didSuffix string, recoveryKey jwx.PublicKeyJWK, signer BTCSignerVerifier) (*DeactivateRequest, error)
NewDeactivateRequest creates a new deactivate request https://identity.foundation/sidetree/spec/#deactivate
func (DeactivateRequest) GetType ¶
func (DeactivateRequest) GetType() OperationType
type DeactivateSignedDataObject ¶
type DeactivateSignedDataObject struct { DIDSuffix string `json:"didSuffix,omitempty"` RecoveryKey jwx.PublicKeyJWK `json:"recoveryKey,omitempty"` }
DeactivateSignedDataObject https://identity.foundation/sidetree/spec/#deactivate-signed-data-object
type Delta ¶
type Delta struct { Patches []Patch `json:"patches,omitempty"` //revive:disable-line UpdateCommitment string `json:"updateCommitment,omitempty"` }
func (*Delta) AddAddPublicKeysAction ¶
func (d *Delta) AddAddPublicKeysAction(patch AddPublicKeysAction)
func (*Delta) AddAddServicesAction ¶
func (d *Delta) AddAddServicesAction(patch AddServicesAction)
func (*Delta) AddRemovePublicKeysAction ¶
func (d *Delta) AddRemovePublicKeysAction(patch RemovePublicKeysAction)
func (*Delta) AddRemoveServicesAction ¶
func (d *Delta) AddRemoveServicesAction(patch RemoveServicesAction)
func (*Delta) AddReplaceAction ¶
func (d *Delta) AddReplaceAction(patch ReplaceAction)
func (*Delta) GetPatches ¶
func (*Delta) UnmarshalJSON ¶
type Document ¶
type ErrorCode ¶
type ErrorCode string
const ( DeltaExceedsMaximumSize ErrorCode = "DeltaExceedsMaximumSize" DIDDocumentPublicKeyIDDuplicated ErrorCode = "DidDocumentPublicKeyIdDuplicated" DIDDocumentPublicKeyMissingOrIncorrectType ErrorCode = "DidDocumentPublicKeyMissingOrIncorrectType" DIDDocumentServiceIDDuplicated ErrorCode = "DidDocumentServiceIdDuplicated" DIDSuffixIncorrectLength ErrorCode = "DidSuffixIncorrectLength" // #nosec EncodedStringIncorrectEncoding ErrorCode = "EncodedStringIncorrectEncoding" IDNotUsingBase64URLCharacterSet ErrorCode = "IdNotUsingBase64UrlCharacterSet" IDTooLong ErrorCode = "IdTooLong" JWKES256kMissingOrInvalidCRV ErrorCode = "JwkEs256kMissingOrInvalidCrv" JWKES256kMissingOrInvalidKTY ErrorCode = "JwkEs256kMissingOrInvalidKty" JWKES256kHasIncorrectLengthOfX ErrorCode = "JwkEs256kHasIncorrectLengthOfX" JWKES256kHasIncorrectLengthOfY ErrorCode = "JwkEs256kHasIncorrectLengthOfY" JWKES256kHasIncorrectLengthOfD ErrorCode = "JwkEs256kHasIncorrectLengthOfD" MultihashStringNotAMultihash ErrorCode = "MultihashStringNotAMultihash" MultihashUnsupportedHashAlgorithm ErrorCode = "MultihashUnsupportedHashAlgorithm" PublicKeyJWKES256kHasUnexpectedProperty ErrorCode = "PublicKeyJwkEs256kHasUnexpectedProperty" PublicKeyPurposeDuplicated ErrorCode = "PublicKeyPurposeDuplicated" ServiceEndpointCannotBeAnArray ErrorCode = "ServiceEndpointCannotBeAnArray" ServiceEndpointStringNotValidURI ErrorCode = "ServiceEndpointStringNotValidUri" ServiceTypeTooLong ErrorCode = "ServiceTypeTooLong" )
type ION ¶
type ION string
type InitialState ¶
type InitialState struct { SuffixData SuffixData `json:"suffixData,omitempty"` Delta Delta `json:"delta,omitempty"` }
InitialState is the initial state of a DID Document as defined in the spec https://identity.foundation/sidetree/spec/#long-form-did-uris
func DecodeLongFormDID ¶
func DecodeLongFormDID(longFormDID string) (string, *InitialState, error)
DecodeLongFormDID decodes a long form DID into a short form DID and its create operation suffix data
func (InitialState) ToDIDStrings ¶
func (is InitialState) ToDIDStrings() (shortFormDID string, longFormDID string, err error)
type LocalResolver ¶
type LocalResolver struct{}
LocalResolver is a resolver that can resolve long form ION DIDs
func (LocalResolver) Methods ¶
func (LocalResolver) Methods() []did.Method
func (LocalResolver) Resolve ¶
func (LocalResolver) Resolve(_ context.Context, id string, _ ...resolution.Option) (*resolution.Result, error)
type OperationKeyType ¶
type OperationKeyType string
const ( Public OperationKeyType = "public" Private OperationKeyType = "private" )
type OperationType ¶
type OperationType string
const ( Create OperationType = "create" Update OperationType = "update" Deactivate OperationType = "deactivate" Recover OperationType = "recover" )
type Patch ¶
type Patch interface {
GetAction() PatchAction
}
type PatchAction ¶
type PatchAction string
const ( Replace PatchAction = "replace" AddPublicKeys PatchAction = "add-public-keys" RemovePublicKeys PatchAction = "remove-public-keys" AddServices PatchAction = "add-services" RemoveServices PatchAction = "remove-services" )
func (PatchAction) String ¶
func (p PatchAction) String() string
type PublicKey ¶
type PublicKey struct { ID string `json:"id,omitempty"` Type string `json:"type,omitempty"` PublicKeyJWK jwx.PublicKeyJWK `json:"publicKeyJwk,omitempty"` Purposes []did.PublicKeyPurpose `json:"purposes,omitempty"` }
type RecoverRequest ¶
type RecoverRequest struct { Type OperationType `json:"type,omitempty"` DIDSuffix string `json:"didSuffix,omitempty"` RevealValue string `json:"revealValue,omitempty"` Delta Delta `json:"delta,omitempty"` SignedData string `json:"signedData,omitempty"` }
func NewRecoverRequest ¶
func NewRecoverRequest(didSuffix string, recoveryKey, nextRecoveryKey, nextUpdateKey jwx.PublicKeyJWK, document Document, signer BTCSignerVerifier) (*RecoverRequest, error)
NewRecoverRequest creates a new recover request https://identity.foundation/sidetree/spec/#recover
func (RecoverRequest) GetType ¶
func (RecoverRequest) GetType() OperationType
type RecoverySignedDataObject ¶
type RecoverySignedDataObject struct { RecoveryCommitment string `json:"recoveryCommitment,omitempty"` RecoveryKey jwx.PublicKeyJWK `json:"recoveryKey,omitempty"` DeltaHash string `json:"deltaHash,omitempty"` AnchorOrigin string `json:"anchorOrigin,omitempty"` }
RecoverySignedDataObject https://identity.foundation/sidetree/spec/#recovery-signed-data-object
type RemovePublicKeysAction ¶
type RemovePublicKeysAction struct { Action PatchAction `json:"action,omitempty"` IDs []string `json:"ids,omitempty"` }
RemovePublicKeysAction https://identity.foundation/sidetree/spec/#add-public-keys
func (RemovePublicKeysAction) GetAction ¶
func (a RemovePublicKeysAction) GetAction() PatchAction
type RemoveServicesAction ¶
type RemoveServicesAction struct { Action PatchAction `json:"action,omitempty"` IDs []string `json:"ids,omitempty"` }
RemoveServicesAction https://identity.foundation/sidetree/spec/#remove-services
func (RemoveServicesAction) GetAction ¶
func (a RemoveServicesAction) GetAction() PatchAction
type ReplaceAction ¶
type ReplaceAction struct { Action PatchAction `json:"action,omitempty"` Document Document `json:"document,omitempty"` }
ReplaceAction https://identity.foundation/sidetree/spec/#replace
func (ReplaceAction) GetAction ¶
func (a ReplaceAction) GetAction() PatchAction
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
func NewIONResolver ¶
NewIONResolver creates a new resolution for the ION DID method with a common base URL The base URL is the URL of the ION node, for example: https://ion.tbd.network The resolution will append the DID to the base URL to resolve the DID such as
https://ion.tbd.network/identifiers/did:ion:1234
and similarly for submitting anchor operations to the ION node...
https://ion.tbd.network/operations
func (Resolver) Anchor ¶
func (i Resolver) Anchor(ctx context.Context, op AnchorOperation) (*resolution.Result, error)
Anchor submits an anchor operation to the ION node by appending the operations path to the base URL and making a POST request
type StateChange ¶
type StateChange struct { ServicesToAdd []did.Service ServiceIDsToRemove []string PublicKeysToAdd []PublicKey PublicKeyIDsToRemove []string }
func (StateChange) IsEmpty ¶
func (s StateChange) IsEmpty() bool
func (StateChange) IsValid ¶
func (s StateChange) IsValid() error
type SuffixData ¶
type UpdateRequest ¶
type UpdateRequest struct { Type OperationType `json:"type,omitempty"` DIDSuffix string `json:"didSuffix,omitempty"` RevealValue string `json:"revealValue,omitempty"` Delta Delta `json:"delta,omitempty"` SignedData string `json:"signedData,omitempty"` }
func NewUpdateRequest ¶
func NewUpdateRequest(didSuffix string, updateKey, nextUpdateKey jwx.PublicKeyJWK, signer BTCSignerVerifier, stateChange StateChange) (*UpdateRequest, error)
NewUpdateRequest creates a new update request https://identity.foundation/sidetree/spec/#update
func (UpdateRequest) GetType ¶
func (UpdateRequest) GetType() OperationType
type UpdateSignedDataObject ¶
type UpdateSignedDataObject struct { UpdateKey jwx.PublicKeyJWK `json:"updateKey,omitempty"` DeltaHash string `json:"deltaHash,omitempty"` }
UpdateSignedDataObject https://identity.foundation/sidetree/spec/#update-signed-data-object