ion

package
v0.0.4-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2023 License: Apache-2.0 Imports: 25 Imported by: 3

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

View Source
const (
	Prefix = "did:ion"
)

Variables

This section is empty.

Functions

func Canonicalize

func Canonicalize(data []byte) ([]byte, error)

Canonicalize transforms JSON according to the protocol's JSON Canonicalization Scheme https://identity.foundation/sidetree/spec/#json-canonicalization-scheme

func CanonicalizeAny

func CanonicalizeAny(data any) ([]byte, error)

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

func CreateShortFormDID(suffixData any) (string, error)

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 Decode

func Decode(data string) ([]byte, error)

Decode decodes according to the encoding scheme of the sidetree spec

func Encode

func Encode(data []byte) string

Encode encodes according to the encoding scheme of the sidetree spec

func EncodeAny

func EncodeAny(data any) (string, error)

EncodeAny encodes any according to the encoding scheme of the sidetree spec

func EncodeString

func EncodeString(data string) string

EncodeString encodes a string according to the encoding scheme of the sidetree spec

func Hash

func Hash(data []byte) []byte

Hash hashes given data according to the protocol's hashing process; not multihashed

func HashEncode

func HashEncode(data []byte) (string, error)

HashEncode hashes given data according to the protocol's hashing process https://identity.foundation/sidetree/spec/#hashing-process

func LongToShortFormDID

func LongToShortFormDID(longFormDID string) (string, error)

LongToShortFormDID returns the short form DID from a long form DID

func Multihash

func Multihash(data []byte) ([]byte, error)

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

type AddServicesAction

type AddServicesAction struct {
	Action   PatchAction `json:"action,omitempty"`
	Services []Service   `json:"services,omitempty"`
}

AddServicesAction https://identity.foundation/sidetree/spec/#add-services

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

func (*BTCSignerVerifier) Verify

func (sv *BTCSignerVerifier) Verify(data, signature []byte) (bool, error)

Verify verifies the given data according to Bitcoin's verification process

func (*BTCSignerVerifier) VerifyJWS

func (sv *BTCSignerVerifier) VerifyJWS(jws string) (bool, error)

VerifyJWS verifies the given data according to the protocol's JWS verification process

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) ID

func (d DID) ID() string

func (DID) IsEmpty

func (d DID) IsEmpty() bool

func (DID) LongForm

func (d DID) LongForm() string

func (DID) Operation

func (d DID) Operation(index int) any

func (DID) Operations

func (d DID) Operations() []any

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          []any  `json:"patches,omitempty"` //revive:disable-line
	UpdateCommitment string `json:"updateCommitment,omitempty"`
}

func NewDelta

func NewDelta(updateCommitment string) Delta

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 (d *Delta) GetPatches() []any

type Document

type Document struct {
	PublicKeys []PublicKey `json:"publicKeys,omitempty"`
	Services   []Service   `json:"services,omitempty"`
}

func (Document) IsEmpty

func (d Document) IsEmpty() bool

type ErrorCode

type ErrorCode string
const (
	DeltaExceedsMaximumSize                    ErrorCode = "DeltaExceedsMaximumSize"
	DIDDocumentPublicKeyIDDuplicated           ErrorCode = "DidDocumentPublicKeyIdDuplicated"
	DIDDocumentPublicKeyMissingOrIncorrectType ErrorCode = "DidDocumentPublicKeyMissingOrIncorrectType"
	DIDDocumentServiceIDDuplicated             ErrorCode = "DidDocumentServiceIdDuplicated"
	DIDSuffixIncorrectLength                   ErrorCode = "DidSuffixIncorrectLength"
	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

func (ION) IsValid

func (d ION) IsValid() bool

IsValid checks if the did:ion is valid by checking for a valid prefix full validation is impossible without resolution

func (ION) Method

func (ION) Method() did.Method

func (ION) String

func (d ION) String() string

func (ION) Suffix

func (d ION) Suffix() (string, error)

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

type Network

type Network string
const (
	Mainnet Network = "mainnet"
	Testnet Network = "testnet"
)

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 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"
)

type PublicKey

type PublicKey struct {
	ID           string             `json:"id,omitempty"`
	Type         string             `json:"type,omitempty"`
	PublicKeyJWK jwx.PublicKeyJWK   `json:"publicKeyJwk,omitempty"`
	Purposes     []PublicKeyPurpose `json:"purposes,omitempty"`
}

type PublicKeyPurpose

type PublicKeyPurpose string
const (
	Authentication       PublicKeyPurpose = "authentication"
	AssertionMethod      PublicKeyPurpose = "assertionMethod"
	CapabilityInvocation PublicKeyPurpose = "capabilityInvocation"
	CapabilityDelegation PublicKeyPurpose = "capabilityDelegation"
	KeyAgreement         PublicKeyPurpose = "keyAgreement"
)

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

type RemoveServicesAction

type RemoveServicesAction struct {
	Action PatchAction `json:"action,omitempty"`
	IDs    []string    `json:"ids,omitempty"`
}

RemoveServicesAction https://identity.foundation/sidetree/spec/#remove-services

type ReplaceAction

type ReplaceAction struct {
	Action   PatchAction `json:"action,omitempty"`
	Document Document    `json:"document,omitempty"`
}

ReplaceAction https://identity.foundation/sidetree/spec/#replace

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

func NewIONResolver

func NewIONResolver(client *http.Client, baseURL string) (*Resolver, error)

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) error

Anchor submits an anchor operation to the ION node by appending the operations path to the base URL and making a POST request

func (Resolver) Resolve

Resolve resolves a did:ion DID by appending the DID to the base URL with the identifiers path and making a GET request

type Service

type Service struct {
	ID              string `json:"id,omitempty"`
	Type            string `json:"type,omitempty"`
	ServiceEndpoint any    `json:"serviceEndpoint,omitempty"`
}

Service declaration in a DID Document

type StateChange

type StateChange struct {
	ServicesToAdd        []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 SuffixData struct {
	DeltaHash          string `json:"deltaHash,omitempty"`
	RecoveryCommitment string `json:"recoveryCommitment,omitempty"`
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL