@veramo/credential-ld 3.1.1-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +6 -0
- package/build/action-handler.d.ts +28 -0
- package/build/action-handler.d.ts.map +1 -0
- package/build/action-handler.js +155 -0
- package/build/action-handler.js.map +1 -0
- package/build/index.d.ts +15 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +31 -0
- package/build/index.js.map +1 -0
- package/build/ld-context-loader.d.ts +16 -0
- package/build/ld-context-loader.d.ts.map +1 -0
- package/build/ld-context-loader.js +40 -0
- package/build/ld-context-loader.js.map +1 -0
- package/build/ld-credential-module.d.ts +25 -0
- package/build/ld-credential-module.d.ts.map +1 -0
- package/build/ld-credential-module.js +148 -0
- package/build/ld-credential-module.js.map +1 -0
- package/build/ld-default-contexts.d.ts +6 -0
- package/build/ld-default-contexts.d.ts.map +1 -0
- package/build/ld-default-contexts.js +60 -0
- package/build/ld-default-contexts.js.map +1 -0
- package/build/ld-suite-loader.d.ts +15 -0
- package/build/ld-suite-loader.d.ts.map +1 -0
- package/build/ld-suite-loader.js +28 -0
- package/build/ld-suite-loader.js.map +1 -0
- package/build/ld-suites.d.ts +13 -0
- package/build/ld-suites.d.ts.map +1 -0
- package/build/ld-suites.js +15 -0
- package/build/ld-suites.js.map +1 -0
- package/build/suites/EcdsaSecp256k1RecoverySignature2020.d.ts +11 -0
- package/build/suites/EcdsaSecp256k1RecoverySignature2020.d.ts.map +1 -0
- package/build/suites/EcdsaSecp256k1RecoverySignature2020.js +100 -0
- package/build/suites/EcdsaSecp256k1RecoverySignature2020.js.map +1 -0
- package/build/suites/Ed25519Signature2018.d.ts +11 -0
- package/build/suites/Ed25519Signature2018.d.ts.map +1 -0
- package/build/suites/Ed25519Signature2018.js +92 -0
- package/build/suites/Ed25519Signature2018.js.map +1 -0
- package/build/tsdoc-metadata.json +11 -0
- package/build/types.d.ts +174 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +3 -0
- package/build/types.js.map +1 -0
- package/contexts/X25519KeyAgreementKey2019.jsonld +26 -0
- package/contexts/did_v0.11.jsonld +58 -0
- package/contexts/ed25519-signature-2018-v1.jsonld +91 -0
- package/contexts/kyc-v1.jsonld +8 -0
- package/contexts/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld +60 -0
- package/contexts/profile-v1.jsonld +8 -0
- package/contexts/security_context_v1.jsonld +58 -0
- package/contexts/socialmedia-v1.jsonld +7 -0
- package/contexts/transmute_v1.jsonld +21 -0
- package/contexts/w3_2018_credentials_v1.jsonld +237 -0
- package/package.json +51 -0
- package/plugin.schema.json +398 -0
- package/src/__tests__/context.loader.test.ts +39 -0
- package/src/__tests__/issue-verify-flow.test.ts +84 -0
- package/src/action-handler.ts +229 -0
- package/src/index.ts +14 -0
- package/src/ld-context-loader.ts +30 -0
- package/src/ld-credential-module.ts +170 -0
- package/src/ld-default-contexts.ts +30 -0
- package/src/ld-suite-loader.ts +29 -0
- package/src/ld-suites.ts +45 -0
- package/src/suites/EcdsaSecp256k1RecoverySignature2020.ts +83 -0
- package/src/suites/Ed25519Signature2018.ts +75 -0
- package/src/types.ts +208 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { RequiredAgentMethods, VeramoLdSignature } from '../ld-suites'
|
|
2
|
+
import { CredentialPayload, DIDDocument, IAgentContext, IKey, TKeyType } from '@veramo/core'
|
|
3
|
+
import {
|
|
4
|
+
EcdsaSecp256k1RecoveryMethod2020,
|
|
5
|
+
EcdsaSecp256k1RecoverySignature2020,
|
|
6
|
+
} from '@transmute/lds-ecdsa-secp256k1-recovery2020'
|
|
7
|
+
|
|
8
|
+
import * as u8a from 'uint8arrays'
|
|
9
|
+
import { asArray, encodeJoseBlob } from '@veramo/utils'
|
|
10
|
+
|
|
11
|
+
export class VeramoEcdsaSecp256k1RecoverySignature2020 extends VeramoLdSignature {
|
|
12
|
+
getSupportedVerificationType(): string {
|
|
13
|
+
return 'EcdsaSecp256k1RecoveryMethod2020'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getSupportedVeramoKeyType(): TKeyType {
|
|
17
|
+
return 'Secp256k1'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getSuiteForSigning(
|
|
21
|
+
key: IKey,
|
|
22
|
+
did: string,
|
|
23
|
+
verifiableMethodId: string,
|
|
24
|
+
context: IAgentContext<RequiredAgentMethods>,
|
|
25
|
+
): any {
|
|
26
|
+
const controller = did
|
|
27
|
+
const signer = {
|
|
28
|
+
//returns a JWS detached
|
|
29
|
+
sign: async (args: { data: Uint8Array }): Promise<string> => {
|
|
30
|
+
const header = {
|
|
31
|
+
alg: 'ES256K-R',
|
|
32
|
+
b64: false,
|
|
33
|
+
crit: ['b64'],
|
|
34
|
+
}
|
|
35
|
+
const headerString = encodeJoseBlob(header)
|
|
36
|
+
const messageBuffer = u8a.concat([u8a.fromString(`${headerString}.`, 'utf-8'), args.data])
|
|
37
|
+
const messageString = u8a.toString(messageBuffer, 'base64')
|
|
38
|
+
const signature = await context.agent.keyManagerSign({
|
|
39
|
+
keyRef: key.kid,
|
|
40
|
+
algorithm: 'ES256K-R',
|
|
41
|
+
data: messageString,
|
|
42
|
+
encoding: 'base64',
|
|
43
|
+
})
|
|
44
|
+
return `${headerString}..${signature}`
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return new EcdsaSecp256k1RecoverySignature2020({
|
|
49
|
+
// signer,
|
|
50
|
+
key: new EcdsaSecp256k1RecoveryMethod2020({
|
|
51
|
+
publicKeyHex: key.publicKeyHex,
|
|
52
|
+
signer: () => signer,
|
|
53
|
+
type: this.getSupportedVerificationType(),
|
|
54
|
+
controller,
|
|
55
|
+
id: verifiableMethodId,
|
|
56
|
+
}),
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
getSuiteForVerification(): any {
|
|
61
|
+
return new EcdsaSecp256k1RecoverySignature2020()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
preSigningCredModification(credential: CredentialPayload): void {
|
|
65
|
+
credential['@context'] = [
|
|
66
|
+
...asArray(credential['@context'] || []),
|
|
67
|
+
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
preDidResolutionModification(didUrl: string, didDoc: DIDDocument): void {
|
|
72
|
+
// did:ethr
|
|
73
|
+
if (didUrl.toLowerCase().startsWith('did:ethr')) {
|
|
74
|
+
// TODO: EcdsaSecp256k1RecoveryMethod2020 does not support blockchainAccountId
|
|
75
|
+
// blockchainAccountId to ethereumAddress
|
|
76
|
+
didDoc.verificationMethod?.forEach((x) => {
|
|
77
|
+
if (x.blockchainAccountId) {
|
|
78
|
+
x.ethereumAddress = x.blockchainAccountId.substring(0, x.blockchainAccountId.lastIndexOf('@'))
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { encodeJoseBlob } from '@veramo/utils'
|
|
2
|
+
import { RequiredAgentMethods, VeramoLdSignature } from '../ld-suites'
|
|
3
|
+
import { CredentialPayload, DIDDocument, IAgentContext, IKey, TKeyType } from '@veramo/core'
|
|
4
|
+
import * as u8a from 'uint8arrays'
|
|
5
|
+
import { Ed25519Signature2018, Ed25519VerificationKey2018 } from '@transmute/ed25519-signature-2018'
|
|
6
|
+
|
|
7
|
+
export class VeramoEd25519Signature2018 extends VeramoLdSignature {
|
|
8
|
+
getSupportedVerificationType(): string {
|
|
9
|
+
return 'Ed25519VerificationKey2018'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
getSupportedVeramoKeyType(): TKeyType {
|
|
13
|
+
return 'Ed25519'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getSuiteForSigning(
|
|
17
|
+
key: IKey,
|
|
18
|
+
issuerDid: string,
|
|
19
|
+
verificationMethodId: string,
|
|
20
|
+
context: IAgentContext<RequiredAgentMethods>,
|
|
21
|
+
): any {
|
|
22
|
+
const controller = issuerDid
|
|
23
|
+
|
|
24
|
+
// DID Key ID
|
|
25
|
+
let id = verificationMethodId
|
|
26
|
+
|
|
27
|
+
const signer = {
|
|
28
|
+
// returns a JWS detached
|
|
29
|
+
sign: async (args: { data: Uint8Array }): Promise<string> => {
|
|
30
|
+
const header = {
|
|
31
|
+
alg: 'EdDSA',
|
|
32
|
+
b64: false,
|
|
33
|
+
crit: ['b64'],
|
|
34
|
+
}
|
|
35
|
+
const headerString = encodeJoseBlob(header)
|
|
36
|
+
const messageBuffer = u8a.concat([u8a.fromString(`${headerString}.`, 'utf-8'), args.data])
|
|
37
|
+
const messageString = u8a.toString(messageBuffer, 'base64')
|
|
38
|
+
const signature = await context.agent.keyManagerSign({
|
|
39
|
+
keyRef: key.kid,
|
|
40
|
+
algorithm: 'EdDSA',
|
|
41
|
+
data: messageString,
|
|
42
|
+
encoding: 'base64',
|
|
43
|
+
})
|
|
44
|
+
return `${headerString}..${signature}`
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const verificationKey = new Ed25519VerificationKey2018({
|
|
49
|
+
id,
|
|
50
|
+
controller,
|
|
51
|
+
publicKey: u8a.fromString(key.publicKeyHex, 'base16'),
|
|
52
|
+
signer: () => signer,
|
|
53
|
+
type: this.getSupportedVerificationType(),
|
|
54
|
+
})
|
|
55
|
+
// overwrite the signer since we're not passing the private key and transmute doesn't support that behavior
|
|
56
|
+
verificationKey.signer = () => signer as any
|
|
57
|
+
|
|
58
|
+
return new Ed25519Signature2018({
|
|
59
|
+
key: verificationKey,
|
|
60
|
+
signer: signer,
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getSuiteForVerification(): any {
|
|
65
|
+
return new Ed25519Signature2018()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
preSigningCredModification(credential: CredentialPayload): void {
|
|
69
|
+
// nothing to do here
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
preDidResolutionModification(didUrl: string, didDoc: DIDDocument): void {
|
|
73
|
+
// nothing to do here
|
|
74
|
+
}
|
|
75
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CredentialPayload,
|
|
3
|
+
IAgentContext,
|
|
4
|
+
IDIDManager,
|
|
5
|
+
IKey,
|
|
6
|
+
IKeyManager,
|
|
7
|
+
IPluginMethodMap,
|
|
8
|
+
IResolver,
|
|
9
|
+
PresentationPayload,
|
|
10
|
+
VerifiableCredential,
|
|
11
|
+
VerifiablePresentation,
|
|
12
|
+
} from '@veramo/core'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The interface definition for a plugin that can issue and verify Verifiable Credentials and Presentations
|
|
16
|
+
* that use JSON-LD format.
|
|
17
|
+
*
|
|
18
|
+
* @remarks Please see {@link https://www.w3.org/TR/vc-data-model | W3C Verifiable Credentials data model}
|
|
19
|
+
*
|
|
20
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
21
|
+
*/
|
|
22
|
+
export interface ICredentialIssuerLD extends IPluginMethodMap {
|
|
23
|
+
/**
|
|
24
|
+
* Creates a Verifiable Presentation.
|
|
25
|
+
* The payload, signer and format are chosen based on the `args` parameter.
|
|
26
|
+
*
|
|
27
|
+
* @param args - Arguments necessary to create the Presentation.
|
|
28
|
+
* @param context - This reserved param is automatically added and handled by the framework, *do not override*
|
|
29
|
+
*
|
|
30
|
+
* @returns - a promise that resolves to the {@link @veramo/core#VerifiablePresentation} that was requested or rejects with an error
|
|
31
|
+
* if there was a problem with the input or while getting the key to sign
|
|
32
|
+
*
|
|
33
|
+
* @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#presentations | Verifiable Presentation data model }
|
|
34
|
+
*
|
|
35
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
36
|
+
*/
|
|
37
|
+
createVerifiablePresentationLD(
|
|
38
|
+
args: ICreateVerifiablePresentationLDArgs,
|
|
39
|
+
context: IRequiredContext,
|
|
40
|
+
): Promise<VerifiablePresentation>
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Creates a Verifiable Credential.
|
|
44
|
+
* The payload, signer and format are chosen based on the `args` parameter.
|
|
45
|
+
*
|
|
46
|
+
* @param args - Arguments necessary to create the Presentation.
|
|
47
|
+
* @param context - This reserved param is automatically added and handled by the framework, *do not override*
|
|
48
|
+
*
|
|
49
|
+
* @returns - a promise that resolves to the {@link @veramo/core#VerifiableCredential} that was requested or rejects with an error
|
|
50
|
+
* if there was a problem with the input or while getting the key to sign
|
|
51
|
+
*
|
|
52
|
+
* @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model}
|
|
53
|
+
*
|
|
54
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
55
|
+
*/
|
|
56
|
+
createVerifiableCredentialLD(
|
|
57
|
+
args: ICreateVerifiableCredentialLDArgs,
|
|
58
|
+
context: IRequiredContext,
|
|
59
|
+
): Promise<VerifiableCredential>
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Verifies a Verifiable Credential JWT or LDS Format.
|
|
63
|
+
*
|
|
64
|
+
* @param args - Arguments necessary to verify a VerifiableCredential
|
|
65
|
+
* @param context - This reserved param is automatically added and handled by the framework, *do not override*
|
|
66
|
+
*
|
|
67
|
+
* @returns - a promise that resolves to the boolean true on successful verification or rejects on error
|
|
68
|
+
*
|
|
69
|
+
* @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model}
|
|
70
|
+
*
|
|
71
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
72
|
+
*/
|
|
73
|
+
verifyCredentialLD(args: IVerifyCredentialLDArgs, context: IRequiredContext): Promise<boolean>
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Verifies a Verifiable Presentation JWT or LDS Format.
|
|
77
|
+
*
|
|
78
|
+
* @param args - Arguments necessary to verify a VerifiableCredential
|
|
79
|
+
* @param context - This reserved param is automatically added and handled by the framework, *do not override*
|
|
80
|
+
*
|
|
81
|
+
* @returns - a promise that resolves to the boolean true on successful verification or rejects on error
|
|
82
|
+
*
|
|
83
|
+
* @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#presentations | Verifiable Credential data model}
|
|
84
|
+
*
|
|
85
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
86
|
+
*/
|
|
87
|
+
verifyPresentationLD(args: IVerifyPresentationLDArgs, context: IRequiredContext): Promise<boolean>
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Encapsulates the parameters required to create a
|
|
92
|
+
* {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation}
|
|
93
|
+
*
|
|
94
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
95
|
+
*/
|
|
96
|
+
export interface ICreateVerifiablePresentationLDArgs {
|
|
97
|
+
/**
|
|
98
|
+
* The json payload of the Presentation according to the
|
|
99
|
+
* {@link https://www.w3.org/TR/vc-data-model/#presentations | canonical model}.
|
|
100
|
+
*
|
|
101
|
+
* The signer of the Presentation is chosen based on the `holder` property
|
|
102
|
+
* of the `presentation`
|
|
103
|
+
*
|
|
104
|
+
* '@context', 'type' and 'issuanceDate' will be added automatically if omitted
|
|
105
|
+
*/
|
|
106
|
+
presentation: PresentationPayload
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Optional (only JWT) string challenge parameter to add to the verifiable presentation.
|
|
110
|
+
*/
|
|
111
|
+
challenge?: string
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Optional string domain parameter to add to the verifiable presentation.
|
|
115
|
+
*/
|
|
116
|
+
domain?: string
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Optional. The key handle ({@link IKey#kid}) from the internal database.
|
|
120
|
+
*/
|
|
121
|
+
keyRef?: string
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Encapsulates the parameters required to create a
|
|
126
|
+
* {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential}
|
|
127
|
+
*
|
|
128
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
129
|
+
*/
|
|
130
|
+
export interface ICreateVerifiableCredentialLDArgs {
|
|
131
|
+
/**
|
|
132
|
+
* The json payload of the Credential according to the
|
|
133
|
+
* {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model}
|
|
134
|
+
*
|
|
135
|
+
* The signer of the Credential is chosen based on the `issuer.id` property
|
|
136
|
+
* of the `credential`
|
|
137
|
+
*
|
|
138
|
+
* '@context', 'type' and 'issuanceDate' will be added automatically if omitted
|
|
139
|
+
*/
|
|
140
|
+
credential: CredentialPayload
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Optional. The key handle ({@link IKey#kid}) from the internal database.
|
|
144
|
+
*/
|
|
145
|
+
keyRef?: string
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Encapsulates the parameters required to verify a
|
|
150
|
+
* {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential}
|
|
151
|
+
*
|
|
152
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
153
|
+
*/
|
|
154
|
+
export interface IVerifyCredentialLDArgs {
|
|
155
|
+
/**
|
|
156
|
+
* The json payload of the Credential according to the
|
|
157
|
+
* {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model}
|
|
158
|
+
*
|
|
159
|
+
* The signer of the Credential is chosen based on the `issuer.id` property
|
|
160
|
+
* of the `credential`
|
|
161
|
+
*
|
|
162
|
+
*/
|
|
163
|
+
credential: VerifiableCredential
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Encapsulates the parameters required to verify a
|
|
168
|
+
* {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation}
|
|
169
|
+
*
|
|
170
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
171
|
+
*/
|
|
172
|
+
export interface IVerifyPresentationLDArgs {
|
|
173
|
+
/**
|
|
174
|
+
* The json payload of the Credential according to the
|
|
175
|
+
* {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model}
|
|
176
|
+
*
|
|
177
|
+
* The signer of the Credential is chosen based on the `issuer.id` property
|
|
178
|
+
* of the `credential`
|
|
179
|
+
*
|
|
180
|
+
*/
|
|
181
|
+
presentation: VerifiablePresentation
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Optional (only for JWT) string challenge parameter to verify the verifiable presentation against
|
|
185
|
+
*/
|
|
186
|
+
challenge?: string
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Optional (only for JWT) string domain parameter to verify the verifiable presentation against
|
|
190
|
+
*/
|
|
191
|
+
domain?: string
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Represents the requirements that this plugin has.
|
|
196
|
+
* The agent that is using this plugin is expected to provide these methods.
|
|
197
|
+
*
|
|
198
|
+
* This interface can be used for static type checks, to make sure your application is properly initialized.
|
|
199
|
+
*
|
|
200
|
+
* @beta This API is likely to change without a BREAKING CHANGE notice
|
|
201
|
+
*/
|
|
202
|
+
export type IRequiredContext = IAgentContext<
|
|
203
|
+
IResolver & Pick<IDIDManager, 'didManagerGet'> & Pick<IKeyManager, 'keyManagerGet' | 'keyManagerSign'>
|
|
204
|
+
>
|
|
205
|
+
|
|
206
|
+
export type ContextDoc = {
|
|
207
|
+
'@context': Record<string, any>
|
|
208
|
+
}
|