Documentation ¶
Overview ¶
Package did Package did-sdk-go provides general purpose operations for MetaBlox according to W3C spec.
Index ¶
- Constants
- Variables
- func CompareAddresses(vm VerificationMethod, pubKey *ecdsa.PublicKey) bool
- func ConvertDocToBytes(doc DIDDocument) []byte
- func ConvertServiceToBytes(service Service) []byte
- func ConvertTimesFromDBFormat(vc *VerifiableCredential) error
- func ConvertTimesToDBFormat(vc *VerifiableCredential) error
- func ConvertVCToBytes(vc VerifiableCredential) []byte
- func ConvertVMToBytes(vm VerificationMethod) []byte
- func ConvertVPToBytes(vp VerifiablePresentation) []byte
- func CreateJWSSignature(privKey *ecdsa.PrivateKey, message []byte) (string, error)
- func DocumentToJson(document *DIDDocument) ([]byte, error)
- func GenerateDIDString(privKey *ecdsa.PrivateKey) string
- func GenerateTestPrivKey() *ecdsa.PrivateKey
- func GetIssuerChainId() *big.Int
- func GetIssuerDid() string
- func GetIssuerPrivateKey() *ecdsa.PrivateKey
- func Init(cfg *Config) error
- func IsDIDValid(did []string) bool
- func PrepareDID(did string) ([]string, bool)
- func Resolve(did string, options *ResolutionOptions, registry *registry.Registry) (*ResolutionMetadata, *DIDDocument, *DocumentMetadata)
- func ResolveRepresentation(did string, options *RepresentationResolutionOptions, ...) (*RepresentationResolutionMetadata, []byte, *DocumentMetadata)
- func SplitDIDString(did string) []string
- func VCToJson(vc *VerifiableCredential) ([]byte, error)
- func VerifyJWSSignature(signature string, pubKey *ecdsa.PublicKey, message []byte) (bool, error)
- func VerifyVC(vc *VerifiableCredential, registry *registry.Registry) (bool, error)
- func VerifyVCSecp256k1(vc *VerifiableCredential, pubKey *ecdsa.PublicKey) (bool, error)
- func VerifyVP(presentation *VerifiablePresentation, registry *registry.Registry) (bool, error)
- func VerifyVPSecp256k1(presentation *VerifiablePresentation, pubKey *ecdsa.PublicKey) (bool, error)
- type Config
- type DIDDocument
- func CreateDID(privKey *ecdsa.PrivateKey) *DIDDocument
- func CreateDIDDocument() *DIDDocument
- func GenerateTestDIDDocument() *DIDDocument
- func GenerateTestResolvedDIDDocument() *DIDDocument
- func GetDocument(targetDID string, registry *registry.Registry) (*DIDDocument, [32]byte, error)
- func JsonToDocument(jsonDoc []byte) (*DIDDocument, error)
- type DocumentMetadata
- type MiningLicenseInfo
- type RepresentationResolutionMetadata
- type RepresentationResolutionOptions
- type ResolutionMetadata
- type ResolutionOptions
- type Service
- type SubjectInfo
- type VCProof
- type VCSchemaChanged
- type VPProof
- type VerifiableCredential
- func CreateVC(issuerDocument *DIDDocument) (*VerifiableCredential, error)
- func CreateVerifiableCredential() *VerifiableCredential
- func GenerateTestMiningLicenseVC() *VerifiableCredential
- func GenerateTestVC() *VerifiableCredential
- func GenerateTestWifiAccessVC() *VerifiableCredential
- func JsonToVC(jsonVC []byte) (*VerifiableCredential, error)
- func NewVerifiableCredential(context []string, id string, vctype []string, ...) *VerifiableCredential
- type VerifiablePresentation
- func CreatePresentation(credentials []VerifiableCredential, holderDocument DIDDocument, ...) (*VerifiablePresentation, error)
- func GenerateTestPresentation() *VerifiablePresentation
- func GenerateTestWifiAccessPresentation() *VerifiablePresentation
- func NewPresentation(context, presentationType []string, credentials []VerifiableCredential, ...) *VerifiablePresentation
- type VerificationMethod
- type WifiAccessInfo
Constants ¶
const BaseIDString = "https://metablox.io/credentials/"
All credential ids use a format of this value plus a number. ex. 'http://metablox.com/credentials/5' Only the number is stored in the db as the ID; the full string is only used in formal credentials
const ContextCredential = "https://www.w3.org/2018/credentials/v1"
const ContextDID = "https://w3id.org/did/v1"
const ContextSecp256k1 = "https://identity.foundation/EcdsaSecp256k1RecoverySignature2020#"
const PurposeAuth = "Authentication"
const Secp256k1Key = "EcdsaSecp256k1RecoveryMethod2020"
const Secp256k1Sig = "EcdsaSecp256k1Signature2019"
const TypeCredential = "VerifiableCredential"
const TypeMining = "MiningLicense"
const TypeWifi = "WifiAccess"
Variables ¶
var ( ErrRenewRevoked = errors.New("VC has been revoked, cannot renew") ErrUnknownIssuer = errors.New("unknown issuer") ErrSecp256k1WrongVMType = errors.New("must use a verification method with a type of 'EcdsaSecp256k1RecoveryMethod2020' to verify a 'EcdsaSecp256k1Signature2019' proof") ErrUnknownProofType = errors.New("unable to verify unknown proof type") ErrMissingVM = errors.New("failed to find verification method") ErrWrongAddress = errors.New("provided public key does not match issuer address") )
Functions ¶
func CompareAddresses ¶
func CompareAddresses(vm VerificationMethod, pubKey *ecdsa.PublicKey) bool
make sure that the address created from pubKey matches the address stored in vm's BlockChainAccountId field
func ConvertDocToBytes ¶
func ConvertDocToBytes(doc DIDDocument) []byte
convert document into byte array so it can be hashed (appears to be unused currently)
func ConvertServiceToBytes ¶
convert service to byte array. Used as part of converting document to bytes
func ConvertTimesFromDBFormat ¶
func ConvertTimesFromDBFormat(vc *VerifiableCredential) error
convert issuance and expiration times of credential from db format to RFC3339
func ConvertTimesToDBFormat ¶
func ConvertTimesToDBFormat(vc *VerifiableCredential) error
convert issuance and expiration times of credential from RFC3339 to db format
func ConvertVCToBytes ¶
func ConvertVCToBytes(vc VerifiableCredential) []byte
convert credential to bytes so it can be hashed
func ConvertVMToBytes ¶
func ConvertVMToBytes(vm VerificationMethod) []byte
convert VM to byte array. Used as part of converting document to bytes
func ConvertVPToBytes ¶
func ConvertVPToBytes(vp VerifiablePresentation) []byte
convert presentation to bytes so it can be hashed
func CreateJWSSignature ¶
func CreateJWSSignature(privKey *ecdsa.PrivateKey, message []byte) (string, error)
use a private key and a message to create a JWS format signature
func DocumentToJson ¶
func DocumentToJson(document *DIDDocument) ([]byte, error)
TODO: check that this function can be safely removed
func GenerateDIDString ¶
func GenerateDIDString(privKey *ecdsa.PrivateKey) string
func GenerateTestPrivKey ¶
func GenerateTestPrivKey() *ecdsa.PrivateKey
func GetIssuerChainId ¶
func GetIssuerDid ¶
func GetIssuerDid() string
func GetIssuerPrivateKey ¶
func GetIssuerPrivateKey() *ecdsa.PrivateKey
func PrepareDID ¶
splits did and checks that it is formatted correctly
func Resolve ¶
func Resolve(did string, options *ResolutionOptions, registry *registry.Registry) (*ResolutionMetadata, *DIDDocument, *DocumentMetadata)
generate the did document that matches the provided did string. Any errors are returned in the ResolutionMetadata. Note that options currently does nothing; including it is a requirement according to W3C specifications, but we don't do anything with it right now
func ResolveRepresentation ¶
func ResolveRepresentation(did string, options *RepresentationResolutionOptions, registry *registry.Registry) (*RepresentationResolutionMetadata, []byte, *DocumentMetadata)
generate a did document and return it in a specific data format (currently just JSON)
func SplitDIDString ¶
split did string into 3 sections. First two should be 'did' and 'metablox', last one wil be the identifier
func VCToJson ¶
func VCToJson(vc *VerifiableCredential) ([]byte, error)
convert credential to a JSON format. Currently unused
func VerifyJWSSignature ¶
verify a JWS format signature using the matching public key and the original message
func VerifyVC ¶
func VerifyVC(vc *VerifiableCredential, registry *registry.Registry) (bool, error)
Need to make sure that the stated issuer of the VC actually created it (using the proof alongside the issuer's verification methods), as well as check that the issuer is a trusted source
func VerifyVCSecp256k1 ¶
func VerifyVCSecp256k1(vc *VerifiableCredential, pubKey *ecdsa.PublicKey) (bool, error)
Verify that the provided public key matches the signature in the proof. Since we've made sure that the address in the issuer vm matches this public key, verifying the signature here proves that the signature was made with the issuer's private key
func VerifyVP ¶
func VerifyVP(presentation *VerifiablePresentation, registry *registry.Registry) (bool, error)
Verify a presentation. Need to first verify the presentation's proof using the holder's DID document. Afterwards, need to verify the proof of each credential included inside the presentation
func VerifyVPSecp256k1 ¶
func VerifyVPSecp256k1(presentation *VerifiablePresentation, pubKey *ecdsa.PublicKey) (bool, error)
Verify that the provided public key matches the signature in the proof. Since we've made sure that the address in the holder vm matches this public key, verifying the signature here proves that the signature was made with the holder's private key
Types ¶
type DIDDocument ¶
type DIDDocument struct { Context []string `json:"@context" mapstructure:"@context"` ID string `json:"id"` Created string `json:"created"` Updated string `json:"updated"` Version int `json:"version"` VerificationMethod []VerificationMethod `json:"verificationMethod"` Authentication string `json:"authentication"` Service []Service `json:"service"` }
func CreateDID ¶
func CreateDID(privKey *ecdsa.PrivateKey) *DIDDocument
TODO: check that this function can be safely removed. The foundation service doesn't need to create new DID documents; however, some other system may want to import this function
func CreateDIDDocument ¶
func CreateDIDDocument() *DIDDocument
func GenerateTestDIDDocument ¶
func GenerateTestDIDDocument() *DIDDocument
func GenerateTestResolvedDIDDocument ¶
func GenerateTestResolvedDIDDocument() *DIDDocument
func GetDocument ¶
func JsonToDocument ¶
func JsonToDocument(jsonDoc []byte) (*DIDDocument, error)
TODO: check that this function can be safely removed
func (*DIDDocument) AddService ¶
func (doc *DIDDocument) AddService(service Service)
func (DIDDocument) RetrieveVerificationMethod ¶
func (doc DIDDocument) RetrieveVerificationMethod(vmID string) (VerificationMethod, error)
type DocumentMetadata ¶
type DocumentMetadata struct { Created string `json:"created"` Updated string `json:"updated"` Deactivated string `json:"deactivated"` NextUpdate string `json:"nextUpdate"` VersionID string `json:"versionId"` NextVersionID string `json:"nextVersionId"` EquivalentID []string `json:"equivalentId"` CanonicalID string `json:"canonicalId"` }
type MiningLicenseInfo ¶
type MiningLicenseInfo struct { CredentialID string `json:"-" db:"CredentialID"` ID string `json:"id" db:"ID"` //id of the user the credential is assigned to Name string `json:"name" db:"Name"` //manufacturer name Model string `json:"model" db:"Model"` Serial string `json:"serial" db:"Serial"` //serial number }
func CreateMiningLicenseInfo ¶
func CreateMiningLicenseInfo() *MiningLicenseInfo
func GenerateTestMiningLicenseInfo ¶
func GenerateTestMiningLicenseInfo() *MiningLicenseInfo
func NewMiningLicenseInfo ¶
func NewMiningLicenseInfo(credentialID, id, name, model, serial string) *MiningLicenseInfo
type RepresentationResolutionOptions ¶
type RepresentationResolutionOptions struct {
Accept string `json:"accept"`
}
type ResolutionMetadata ¶
type ResolutionMetadata struct {
Error string `json:"error"`
}
type ResolutionOptions ¶
type ResolutionOptions struct {
Accept string `json:"accept"`
}
func CreateResolutionOptions ¶
func CreateResolutionOptions() *ResolutionOptions
type Service ¶
type Service struct { ID string `json:"id"` Type string `json:"type"` ServiceEndpoint string `json:"serviceEndpoint"` }
func CreateService ¶
func CreateService() *Service
type SubjectInfo ¶
type SubjectInfo struct { ID string `json:"id"` GivenName string `json:"givenName"` FamilyName string `json:"familyName"` Gender string `json:"gender"` BirthCountry string `json:"birthCountry"` BirthDate string `json:"birthName"` }
This can be a type of input form to set up the VC. Temp fields here currently, will be changed in the future
func CreateSubjectInfo ¶
func CreateSubjectInfo() *SubjectInfo
func GenerateTestSubjectInfo ¶
func GenerateTestSubjectInfo() *SubjectInfo
func NewSubjectInfo ¶
func NewSubjectInfo(id string, givenName, familyName, gender, birthCountry, birthDate string) *SubjectInfo
type VCProof ¶
type VCProof struct { Type string `json:"type"` Created string `json:"created"` VerificationMethod string `json:"verificationMethod"` ProofPurpose string `json:"proofPurpose"` JWSSignature string `json:"jws"` //signature is created from a hash of the VC PublicKeyString []byte `json:"publicKeyString"` //public key (belonging to issuer) used for verification }
func CreateProof ¶
create a credential proof using the provided verification method string
func CreateVCProof ¶
func CreateVCProof() *VCProof
func NewVCProof ¶
type VCSchemaChanged ¶
type VPProof ¶
type VPProof struct { Type string `json:"type"` Created string `json:"created"` VerificationMethod string `json:"verificationMethod"` ProofPurpose string `json:"proofPurpose"` JWSSignature string `json:"jws"` //signature is created from a hash of the VP Nonce string `json:"nonce"` //random value generated by verifier that must be included in proof PublicKeyString []byte `json:"publicKeyString"` //public key (belonging to holder) used for verification }
func CreateVPProof ¶
func CreateVPProof() *VPProof
func NewVPProof ¶
type VerifiableCredential ¶
type VerifiableCredential struct { Context []string `json:"@context" mapstructure:"@context"` ID string `json:"id" db:"ID"` Type []string `json:"type"` Issuer string `json:"issuer" db:"Issuer"` IssuanceDate string `json:"issuanceDate" db:"IssuanceDate"` ExpirationDate string `json:"expirationDate" db:"ExpirationDate"` Description string `json:"description" db:"Description"` CredentialSubject interface{} `json:"credentialSubject"` Proof VCProof `json:"proof"` Revoked bool `json:"revoked" db:"Revoked"` }
func CreateVC ¶
func CreateVC(issuerDocument *DIDDocument) (*VerifiableCredential, error)
Base function for creating VCs. Called by any function that creates a type of VC to initialize universal values
func CreateVerifiableCredential ¶
func CreateVerifiableCredential() *VerifiableCredential
func GenerateTestMiningLicenseVC ¶
func GenerateTestMiningLicenseVC() *VerifiableCredential
func GenerateTestVC ¶
func GenerateTestVC() *VerifiableCredential
func GenerateTestWifiAccessVC ¶
func GenerateTestWifiAccessVC() *VerifiableCredential
func JsonToVC ¶
func JsonToVC(jsonVC []byte) (*VerifiableCredential, error)
convert JSON formatted credential to object. Currently unused
func NewVerifiableCredential ¶
type VerifiablePresentation ¶
type VerifiablePresentation struct { Context []string `json:"@context" mapstructure:"@context"` Type []string `json:"type"` VerifiableCredential []VerifiableCredential `json:"verifiableCredential"` Holder string `json:"holder"` Proof VPProof `json:"proof"` }
func CreatePresentation ¶
func CreatePresentation(credentials []VerifiableCredential, holderDocument DIDDocument, holderPrivKey *ecdsa.PrivateKey, nonce string) (*VerifiablePresentation, error)
create a presentation using 1 or more credentials. Currently unused
func GenerateTestPresentation ¶
func GenerateTestPresentation() *VerifiablePresentation
func GenerateTestWifiAccessPresentation ¶
func GenerateTestWifiAccessPresentation() *VerifiablePresentation
func NewPresentation ¶
func NewPresentation(context, presentationType []string, credentials []VerifiableCredential, holder string, proof VPProof) *VerifiablePresentation
type VerificationMethod ¶
type WifiAccessInfo ¶
type WifiAccessInfo struct { CredentialID string `json:"-" db:"CredentialID"` ID string `json:"id" db:"ID"` //id of the user the credential is assigned to Type string `json:"type" db:"Type"` //user or validator }
func CreateWifiAccessInfo ¶
func CreateWifiAccessInfo() *WifiAccessInfo
func GenerateTestWifiAccessInfo ¶
func GenerateTestWifiAccessInfo() *WifiAccessInfo
func NewWifiAccessInfo ¶
func NewWifiAccessInfo(credentialID, id, userType string) *WifiAccessInfo