@sphereon/ssi-sdk.ebsi-support 0.27.0 → 0.27.1-next.12

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.
Files changed (45) hide show
  1. package/dist/agent/EbsiSupport.d.ts +2 -0
  2. package/dist/agent/EbsiSupport.d.ts.map +1 -1
  3. package/dist/agent/EbsiSupport.js +213 -185
  4. package/dist/agent/EbsiSupport.js.map +1 -1
  5. package/dist/did/EbsiDidProvider.d.ts.map +1 -1
  6. package/dist/did/EbsiDidProvider.js +174 -136
  7. package/dist/did/EbsiDidProvider.js.map +1 -1
  8. package/dist/did/EbsiDidResolver.js +19 -6
  9. package/dist/did/EbsiDidResolver.js.map +1 -1
  10. package/dist/did/functions.d.ts +3 -9
  11. package/dist/did/functions.d.ts.map +1 -1
  12. package/dist/did/functions.js +158 -120
  13. package/dist/did/functions.js.map +1 -1
  14. package/dist/did/index.js +28 -5
  15. package/dist/did/index.js.map +1 -1
  16. package/dist/did/services/EbsiRPCService.js +36 -20
  17. package/dist/did/services/EbsiRPCService.js.map +1 -1
  18. package/dist/did/services/EbsiRestService.js +37 -19
  19. package/dist/did/services/EbsiRestService.js.map +1 -1
  20. package/dist/did/types.d.ts +9 -1
  21. package/dist/did/types.d.ts.map +1 -1
  22. package/dist/did/types.js +10 -7
  23. package/dist/did/types.js.map +1 -1
  24. package/dist/functions/Attestation.js +79 -69
  25. package/dist/functions/Attestation.js.map +1 -1
  26. package/dist/functions/AttestationHeadlessCallbacks.js +91 -72
  27. package/dist/functions/AttestationHeadlessCallbacks.js.map +1 -1
  28. package/dist/functions/index.js +32 -4
  29. package/dist/functions/index.js.map +1 -1
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +26 -6
  33. package/dist/index.js.map +1 -1
  34. package/dist/types/IEbsiSupport.d.ts +2 -0
  35. package/dist/types/IEbsiSupport.d.ts.map +1 -1
  36. package/dist/types/IEbsiSupport.js +5 -2
  37. package/dist/types/IEbsiSupport.js.map +1 -1
  38. package/package.json +13 -12
  39. package/plugin.schema.json +2030 -0
  40. package/src/agent/EbsiSupport.ts +17 -1
  41. package/src/did/EbsiDidProvider.ts +19 -1
  42. package/src/did/functions.ts +5 -12
  43. package/src/did/types.ts +9 -2
  44. package/src/index.ts +1 -1
  45. package/src/types/IEbsiSupport.ts +3 -0
@@ -5,7 +5,8 @@ import { IPEXFilterResult } from '@sphereon/ssi-sdk.presentation-exchange'
5
5
  import { CredentialMapper, PresentationSubmission } from '@sphereon/ssi-types'
6
6
  import { IAgentPlugin } from '@veramo/core'
7
7
  import fetch from 'cross-fetch'
8
- import { determineWellknownEndpoint, ebsiGetIssuerMock } from '../did/functions'
8
+ import { CreateEbsiDidOnLedgerResult, CreateEbsiDidParams } from '../did'
9
+ import { determineWellknownEndpoint, ebsiCreateDidOnLedger as ebsiCreateDidOnLedgerFunction, ebsiGetIssuerMock } from '../did/functions'
9
10
  import { ebsiCreateAttestationAuthRequestURL, ebsiGetAttestation } from '../functions'
10
11
  import {
11
12
  ApiOpts,
@@ -30,9 +31,20 @@ import {
30
31
 
31
32
  import { v4 } from 'uuid'
32
33
 
34
+ export const ebsiSupportMethods: Array<string> = [
35
+ 'ebsiCreateDidOnLedger',
36
+ 'ebsiWellknownMetadata',
37
+ 'ebsiAuthorizationServerJwks',
38
+ 'ebsiPresentationDefinitionGet',
39
+ 'ebsiAccessTokenGet',
40
+ 'ebsiCreateAttestationAuthRequestURL',
41
+ 'ebsiGetAttestation',
42
+ ]
43
+
33
44
  export class EbsiSupport implements IAgentPlugin {
34
45
  readonly schema = schema.IEbsiSupport
35
46
  readonly methods: IEbsiSupport = {
47
+ ebsiCreateDidOnLedger: this.ebsiCreateDidOnLedger.bind(this),
36
48
  ebsiWellknownMetadata: this.ebsiWellknownMetadata.bind(this),
37
49
  ebsiAuthorizationServerJwks: this.ebsiAuthorizationServerJwks.bind(this),
38
50
  ebsiPresentationDefinitionGet: this.ebsiPresentationDefinitionGet.bind(this),
@@ -41,6 +53,10 @@ export class EbsiSupport implements IAgentPlugin {
41
53
  ebsiGetAttestation: ebsiGetAttestation.bind(this),
42
54
  }
43
55
 
56
+ private async ebsiCreateDidOnLedger(args: CreateEbsiDidParams, context: IRequiredContext): Promise<CreateEbsiDidOnLedgerResult> {
57
+ return await ebsiCreateDidOnLedgerFunction(args, context)
58
+ }
59
+
44
60
  private async ebsiWellknownMetadata(args: WellknownOpts): Promise<GetOIDProviderMetadataResponse> {
45
61
  const url = determineWellknownEndpoint(args)
46
62
  return await (
@@ -35,6 +35,7 @@ export class EbsiDidProvider extends AbstractIdentifierProvider {
35
35
  notAfter,
36
36
  secp256k1Key,
37
37
  secp256r1Key,
38
+ keys,
38
39
  accessTokenOpts,
39
40
  executeLedgerOperation = !!args.options?.accessTokenOpts,
40
41
  methodSpecificId = generateEbsiMethodSpecificId(EBSI_DID_SPEC_INFOS.V1),
@@ -48,9 +49,11 @@ export class EbsiDidProvider extends AbstractIdentifierProvider {
48
49
  const rpcId = options?.rpcId ?? randomRpcId()
49
50
 
50
51
  if (type === EBSI_DID_SPEC_INFOS.KEY) {
51
- throw new Error(`Type ${type} not supported. Please use @sphereon/ssi-sdk-ext.did-provider-key for Natural Person EBSI DIDs`)
52
+ return Promise.reject(Error(`Type ${type} not supported. Please use @sphereon/ssi-sdk-ext.did-provider-key for Natural Person EBSI DIDs`))
52
53
  } else if (!kms) {
53
54
  return Promise.reject(Error(`No KMS value provided`))
55
+ } else if (keys && keys.length > 0 && !executeLedgerOperation) {
56
+ return Promise.reject(Error(`Cannot add additional keys if ledger operation is not enabled at creation. Please add the keys later yourself`))
54
57
  }
55
58
 
56
59
  // CapabilityInvocation purpose
@@ -95,6 +98,7 @@ export class EbsiDidProvider extends AbstractIdentifierProvider {
95
98
  }
96
99
 
97
100
  if (executeLedgerOperation) {
101
+ // This can only work if we enable global jwks hosting. DID JWK hosting will not work as the DID is not registered at this point
98
102
  await ebsiCreateDidOnLedger(
99
103
  {
100
104
  identifier,
@@ -106,6 +110,20 @@ export class EbsiDidProvider extends AbstractIdentifierProvider {
106
110
  },
107
111
  context,
108
112
  )
113
+ if (keys && keys.length > 0) {
114
+ for (const keyOpts of keys) {
115
+ const key = await ebsiGenerateOrUseKeyPair(
116
+ {
117
+ keyOpts,
118
+ keyType: keyOpts.type ?? 'Secp256r1',
119
+ kms,
120
+ },
121
+ context,
122
+ )
123
+ const managedKeyInfo = await context.agent.keyManagerImport(key)
124
+ console.warn(`FIXME: Anchor additional key on EBSI`, managedKeyInfo)
125
+ }
126
+ }
109
127
  }
110
128
 
111
129
  debug('Created', identifier.did)
@@ -3,7 +3,7 @@ import { CreateRequestObjectMode } from '@sphereon/oid4vci-common'
3
3
  import { getControllerKey, getEthereumAddressFromKey, getKeys } from '@sphereon/ssi-sdk-ext.did-utils'
4
4
  import { calculateJwkThumbprint, calculateJwkThumbprintForKey, JwkKeyUse, toJwk } from '@sphereon/ssi-sdk-ext.key-utils'
5
5
  import { W3CVerifiableCredential } from '@sphereon/ssi-types'
6
- import { IAgentContext, IIdentifier, IKey, IKeyManager, MinimalImportableKey, TKeyType } from '@veramo/core'
6
+ import { IAgentContext, IKey, IKeyManager, MinimalImportableKey, TKeyType } from '@veramo/core'
7
7
  import { getBytes, SigningKey, Transaction } from 'ethers'
8
8
  import { base58btc } from 'multiformats/bases/base58'
9
9
  import * as u8a from 'uint8arrays'
@@ -14,6 +14,7 @@ import { ebsiWaitTillDocumentAnchored } from './services/EbsiRestService'
14
14
  import { callRpcMethod } from './services/EbsiRPCService'
15
15
  import {
16
16
  BASE_CONTEXT_DOC,
17
+ CreateEbsiDidOnLedgerResult,
17
18
  CreateEbsiDidParams,
18
19
  EBSI_DID_SPEC_INFOS,
19
20
  EbsiDidRegistryAPIEndpoints,
@@ -253,7 +254,8 @@ export const assertedPurposes = (args: { key?: IKeyOpts }): EbsiPublicKeyPurpose
253
254
  if (
254
255
  key?.purposes &&
255
256
  key.purposes.length > 0 &&
256
- key.purposes.every((purpose) => [EbsiPublicKeyPurpose.AssertionMethod, EbsiPublicKeyPurpose.Authentication].includes(purpose))
257
+ key.purposes.includes(EbsiPublicKeyPurpose.AssertionMethod) &&
258
+ key.purposes.includes(EbsiPublicKeyPurpose.Authentication)
257
259
  ) {
258
260
  return key.purposes
259
261
  }
@@ -287,16 +289,7 @@ export const randomRpcId = (): number => {
287
289
  return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)
288
290
  }
289
291
 
290
- export const ebsiCreateDidOnLedger = async (
291
- args: CreateEbsiDidParams,
292
- context: IRequiredContext,
293
- ): Promise<{
294
- identifier: IIdentifier
295
- addVerificationMethod: EbsiRPCResponse
296
- insertDidDoc: EbsiRPCResponse
297
- addAssertionMethodRelationship: EbsiRPCResponse
298
- addAuthenticationRelationship: EbsiRPCResponse
299
- }> => {
292
+ export const ebsiCreateDidOnLedger = async (args: CreateEbsiDidParams, context: IRequiredContext): Promise<CreateEbsiDidOnLedgerResult> => {
300
293
  const {
301
294
  accessTokenOpts,
302
295
  notBefore = Math.floor(Date.now() / 1000 - 60),
package/src/did/types.ts CHANGED
@@ -83,6 +83,7 @@ export type EbsiCreateIdentifierOpts = {
83
83
  rpcId?: number
84
84
  secp256k1Key?: IKeyOpts
85
85
  secp256r1Key?: IKeyOpts
86
+ keys?: IKeyOpts[] // additional importable keys, but only in case execute ledger is true
86
87
  executeLedgerOperation?: boolean // Whether to persist on the EBSI ledger. By default looks at whether access token opts are set or not
87
88
  baseDocument?: string
88
89
  notBefore?: number
@@ -379,7 +380,7 @@ export type GetDidDocumentsResponse = {
379
380
  links: Links
380
381
  }
381
382
 
382
- type EbsiAccessTokenOpts = {
383
+ export type EbsiAccessTokenOpts = {
383
384
  attestationToOnboard?: W3CVerifiableCredential
384
385
  jwksUri?: string
385
386
  redirectUri: string
@@ -408,7 +409,13 @@ export type CreateEbsiDidParams = {
408
409
  baseDocument?: string
409
410
  accessTokenOpts: EbsiAccessTokenOpts
410
411
  }
411
-
412
+ export interface CreateEbsiDidOnLedgerResult {
413
+ identifier: IIdentifier
414
+ addVerificationMethod: EbsiRPCResponse
415
+ insertDidDoc: EbsiRPCResponse
416
+ addAssertionMethodRelationship: EbsiRPCResponse
417
+ addAuthenticationRelationship: EbsiRPCResponse
418
+ }
412
419
  /**
413
420
  * @constant JSON_RPC_VERSION
414
421
  */
package/src/index.ts CHANGED
@@ -3,6 +3,6 @@ import { Loggers } from '@sphereon/ssi-types'
3
3
  export const logger = Loggers.DEFAULT.get('sphereon:ebsi-support')
4
4
  const schema = require('../plugin.schema.json')
5
5
  export { schema }
6
- export { EbsiSupport } from './agent/EbsiSupport'
6
+ export { EbsiSupport, ebsiSupportMethods } from './agent/EbsiSupport'
7
7
  export * from './types/IEbsiSupport'
8
8
  export { EbsiDidProvider } from './did'
@@ -8,6 +8,7 @@ import { IPresentationExchange } from '@sphereon/ssi-sdk.presentation-exchange'
8
8
  import { IDidAuthSiopOpAuthenticator } from '@sphereon/ssi-sdk.siopv2-oid4vp-op-auth'
9
9
  import { PresentationSubmission, W3CVerifiableCredential } from '@sphereon/ssi-types'
10
10
  import { IAgentContext, IDIDManager, IIdentifier, IKeyManager, IPluginMethodMap, IResolver } from '@veramo/core'
11
+ import { CreateEbsiDidOnLedgerResult, CreateEbsiDidParams } from '../did'
11
12
  import { AttestationAuthRequestUrlResult } from '../functions'
12
13
 
13
14
  /**
@@ -40,6 +41,8 @@ export type ApiOpts = { environment?: EbsiEnvironment; version: EbsiApiVersion }
40
41
  export type WellknownOpts = ApiOpts & { type: WellknownType; system?: EbsiSystem | EbsiEnvironment; mock?: EbsiMock }
41
42
 
42
43
  export interface IEbsiSupport extends IPluginMethodMap {
44
+ ebsiCreateDidOnLedger(args: CreateEbsiDidParams, context: IRequiredContext): Promise<CreateEbsiDidOnLedgerResult>
45
+
43
46
  ebsiWellknownMetadata(args?: ApiOpts): Promise<GetOIDProviderMetadataResponse>
44
47
 
45
48
  ebsiAuthorizationServerJwks(args?: ApiOpts): Promise<GetOIDProviderJwksResponse>