@sphereon/did-provider-oyd 0.28.1-feature.esm.cjs.8 → 0.28.1-feature.oyd.cmsm.improv.16

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.
@@ -1,10 +1,19 @@
1
- import { IIdentifier, IKey, IService, IAgentContext, IKeyManager } from '@veramo/core'
1
+ import { IIdentifier, IKey, IService, IAgentContext, IKeyManager, TKeyType } from '@veramo/core'
2
2
  import { AbstractIdentifierProvider } from '@veramo/did-manager'
3
- import type { OydCreateIdentifierOptions, OydDidHoldKeysArgs, OydDidSupportedKeyTypes } from './types/oyd-provider-types.js'
3
+ import { KeyManager } from '@veramo/key-manager'
4
+ import type {
5
+ OydCreateIdentifierOptions,
6
+ OydDidHoldKeysArgs,
7
+ OydDidSupportedKeyTypes,
8
+ CMSMCallbackOpts,
9
+ OydConstructorOptions,
10
+ } from './types/oyd-provider-types.js'
4
11
  import fetch from 'cross-fetch'
5
12
 
6
13
  import Debug from 'debug'
14
+
7
15
  const debug = Debug('veramo:oyd-did:identifier-provider')
16
+ const OYDID_REGISTRAR_URL = 'https://oydid-registrar.data-container.net/1.0/createIdentifier'
8
17
 
9
18
  type IContext = IAgentContext<IKeyManager>
10
19
 
@@ -13,23 +22,48 @@ type IContext = IAgentContext<IKeyManager>
13
22
  * @public
14
23
  */
15
24
  export class OydDIDProvider extends AbstractIdentifierProvider {
16
- private defaultKms?: string
25
+ private readonly defaultKms?: string
26
+ private readonly cmsmCallbackOpts?: CMSMCallbackOpts
17
27
 
18
- constructor(options: { defaultKms?: string }) {
28
+ constructor(options?: OydConstructorOptions) {
19
29
  super()
20
- this.defaultKms = options.defaultKms
30
+ this.defaultKms = options?.defaultKms
31
+ this.cmsmCallbackOpts = options?.clientManagedSecretMode
32
+ }
33
+
34
+ private async assertedKms(...kms: (string | undefined)[]): Promise<string> {
35
+ if (!kms || kms.length === 0) {
36
+ return Promise.reject(Error('KMS must be provided either as a parameter or via defaultKms.'))
37
+ }
38
+ const result = kms.find((k) => !!k)
39
+ if (!result) {
40
+ return Promise.reject(Error('KMS must be provided either as a parameter or via defaultKms.'))
41
+ }
42
+ return result
21
43
  }
22
44
 
23
45
  async createIdentifier(
24
46
  { kms, options }: { kms?: string; options: OydCreateIdentifierOptions },
25
47
  context: IContext
26
48
  ): Promise<Omit<IIdentifier, 'provider'>> {
27
- const body = { options }
28
- const url = 'https://oydid-registrar.data-container.net/1.0/createIdentifier'
49
+ const resolvedKms = await this.assertedKms(kms, this.defaultKms)
29
50
 
51
+ if ((this.cmsmCallbackOpts && !options.cmsm) || (options.cmsm && options.cmsm.enabled !== false)) {
52
+ if (!this.cmsmCallbackOpts) {
53
+ return Promise.reject(Error('did:oyd: no cmsm options defined on oyd did provider, but cmsm was enabled on the call!'))
54
+ }
55
+ return await this.createIdentifierWithCMSM({ kms: resolvedKms, options }, context)
56
+ }
57
+
58
+ const body = {
59
+ options: {
60
+ cmsm: false,
61
+ key_type: options.keyType ?? 'Secp256r1',
62
+ },
63
+ }
30
64
  let didDoc: any | undefined
31
65
  try {
32
- const response = await fetch(url, {
66
+ const response = await fetch(OYDID_REGISTRAR_URL, {
33
67
  method: 'POST',
34
68
  headers: {
35
69
  'Content-Type': 'application/json',
@@ -37,19 +71,19 @@ export class OydDIDProvider extends AbstractIdentifierProvider {
37
71
  body: JSON.stringify(body),
38
72
  })
39
73
  if (!response.ok) {
40
- throw new Error('Network response was not ok: ' + response.statusText)
74
+ debug('Error response from OydDID Registrar: ', response)
75
+ return Promise.reject(Error('Network response was not ok: ' + response.statusText))
41
76
  }
42
77
  didDoc = await response.json()
43
- } catch (error) {
44
- // @ts-ignore
45
- throw new Error('There has been a problem with the fetch operation: ' + error.toString())
78
+ } catch (error: any) {
79
+ debug('Unexpected error from OydDID Registrar: ', error)
80
+ return Promise.reject(Error('There has been a problem with the fetch operation: ' + error.toString()))
46
81
  }
47
82
 
48
- const keyType: OydDidSupportedKeyTypes = options?.keyType || 'Ed25519'
49
- const key = await this.holdKeys(
83
+ const keyType: OydDidSupportedKeyTypes = options?.keyType ?? 'Secp256r1'
84
+ const key = await this.importOrCreateKey(
50
85
  {
51
- // @ts-ignore
52
- kms: kms || this.defaultKms,
86
+ kms: resolvedKms,
53
87
  options: {
54
88
  keyType,
55
89
  kid: didDoc.did + '#key-doc',
@@ -70,6 +104,106 @@ export class OydDIDProvider extends AbstractIdentifierProvider {
70
104
  return identifier
71
105
  }
72
106
 
107
+ async createIdentifierWithCMSM(
108
+ { kms, options }: { kms?: string; options: OydCreateIdentifierOptions },
109
+ context: IContext
110
+ ): Promise<Omit<IIdentifier, 'provider'>> {
111
+ const cmsmCallbackOpts = this.cmsmCallbackOpts
112
+ if (!cmsmCallbackOpts) {
113
+ return Promise.reject(Error('did:oyd: no cmsm options defined!'))
114
+ }
115
+
116
+ const assertedKms = await this.assertedKms(kms, this.defaultKms)
117
+ const pubKey =
118
+ options.key ??
119
+ (await cmsmCallbackOpts.publicKeyCallback(options.kid ?? 'default', assertedKms, options.cmsm?.create !== false, options.keyType)) // "default" is probably not right, TODO!!
120
+ const kid = pubKey.kid
121
+ const keyType = pubKey.type
122
+
123
+ let signValue: any | undefined // do the request
124
+ try {
125
+ const body_create = {
126
+ // specify the Identifier options for the registrar
127
+ key: kid,
128
+ options: {
129
+ cmsm: true,
130
+ key_type: keyType,
131
+ },
132
+ }
133
+ const response = await fetch(OYDID_REGISTRAR_URL, {
134
+ method: 'POST',
135
+ headers: {
136
+ 'Content-Type': 'application/json',
137
+ },
138
+ body: JSON.stringify(body_create),
139
+ })
140
+ if (!response.ok) {
141
+ debug('Error response from OydDID Registrar: ', body_create, response)
142
+ return Promise.reject(Error('Network response was not ok: ' + response.statusText))
143
+ }
144
+ signValue = await response.json()
145
+ } catch (error: any) {
146
+ debug('Unexpected error from OydDID Registrar: ', error)
147
+ return Promise.reject(Error('There has been a problem with the fetch operation: ' + error.toString()))
148
+ }
149
+
150
+ // we received our value to sign, now we sign it!
151
+ const { sign } = signValue
152
+ const signature = await cmsmCallbackOpts.signCallback(kid, sign)
153
+
154
+ const body_signed = {
155
+ key: kid,
156
+ options: {
157
+ cmsm: true,
158
+ sig: signature,
159
+ },
160
+ }
161
+
162
+ Object.assign(body_signed.options, options)
163
+
164
+ let didDoc: any | undefined // do the request
165
+ try {
166
+ const response = await fetch(OYDID_REGISTRAR_URL, {
167
+ method: 'POST',
168
+ headers: {
169
+ 'Content-Type': 'application/json',
170
+ },
171
+ body: JSON.stringify(body_signed),
172
+ })
173
+ if (!response.ok) {
174
+ debug('Error response from OydDID Registrar: ', response)
175
+ return Promise.reject(Error('Network response was not ok: ' + response.statusText))
176
+ }
177
+ didDoc = await response.json()
178
+ } catch (error: any) {
179
+ debug('Unexpected error from OydDID Registrar: ', error)
180
+ return Promise.reject(Error('There has been a problem with the fetch operation: ' + error.toString()))
181
+ }
182
+
183
+ /* let oydKeyType: OydDidSupportedKeyTypes = "Secp256r1";
184
+
185
+ const key = await this.holdKeys(
186
+ {
187
+ kms: assertedKms,
188
+ options: {
189
+ keyType: oydKeyType,
190
+ kid: kid,
191
+ publicKeyHex: pubKey.publicKeyHex,
192
+ },
193
+ },
194
+ context
195
+ );*/
196
+
197
+ const identifier: Omit<IIdentifier, 'provider'> = {
198
+ did: didDoc.did,
199
+ controllerKeyId: pubKey.kid,
200
+ keys: [pubKey],
201
+ services: [],
202
+ }
203
+ debug('Created', identifier.did)
204
+ return identifier
205
+ }
206
+
73
207
  async updateIdentifier(
74
208
  args: { did: string; kms?: string | undefined; alias?: string | undefined; options?: any },
75
209
  context: IAgentContext<IKeyManager>
@@ -100,26 +234,61 @@ export class OydDIDProvider extends AbstractIdentifierProvider {
100
234
  return { success: true }
101
235
  }
102
236
 
103
- private async holdKeys(args: OydDidHoldKeysArgs, context: IContext): Promise<IKey> {
237
+ private async importOrCreateKey(args: OydDidHoldKeysArgs, context: IContext): Promise<IKey> {
238
+ const kms = await this.assertedKms(args.kms, this.defaultKms)
104
239
  if (args.options.privateKeyHex) {
105
240
  return context.agent.keyManagerImport({
106
- // @ts-ignore
107
- kms: args.kms || this.defaultKms,
241
+ kms,
108
242
  type: args.options.keyType,
109
243
  kid: args.options.kid,
110
244
  privateKeyHex: args.options.privateKeyHex,
111
- meta: {
112
- algorithms: ['Ed25519'],
113
- },
245
+ /*meta: {
246
+ algorithms: ['Secp256r1'],
247
+ },*/
114
248
  })
115
249
  }
116
250
  return context.agent.keyManagerCreate({
117
251
  type: args.options.keyType,
118
- // @ts-ignore
119
- kms: args.kms || this.defaultKms,
252
+ kms,
120
253
  meta: {
121
- algorithms: ['Ed25519'],
254
+ algorithms: ['Secp256r1'],
122
255
  },
123
256
  })
124
257
  }
125
258
  }
259
+
260
+ export function defaultOydCmsmPublicKeyCallback(
261
+ keyManager: KeyManager
262
+ ): (kid: string, kms?: string, create?: boolean, createKeyType?: TKeyType) => Promise<IKey> {
263
+ return async (kid: string, kms?: string, create?: boolean, createKeyType?: TKeyType): Promise<IKey> => {
264
+ try {
265
+ const existing = await keyManager.keyManagerGet({ kid })
266
+ if (existing) {
267
+ return existing
268
+ }
269
+ } catch (error: any) {}
270
+ if (create) {
271
+ if (!kms) {
272
+ return Promise.reject(Error('No KMS provided, whilst creating a new key!'))
273
+ }
274
+ return await keyManager.keyManagerCreate({ kms, type: createKeyType ?? 'Secp256r1' })
275
+ }
276
+ return Promise.reject(Error('No existing key found, and create is false!'))
277
+ }
278
+ }
279
+
280
+ export function defaultOydCmsmSignCallback(keyManager: KeyManager): (kid: string, data: string) => Promise<string> {
281
+ return async (kid: string, data: string): Promise<string> => {
282
+ return keyManager.keyManagerSign({ keyRef: kid, data, encoding: 'base64' })
283
+ }
284
+ }
285
+
286
+ export class DefaultOydCmsmCallbacks implements CMSMCallbackOpts {
287
+ constructor(private keyManager: KeyManager) {}
288
+
289
+ publicKeyCallback: (kid: string, kms?: string, create?: boolean, createKeyType?: TKeyType) => Promise<IKey> = defaultOydCmsmPublicKeyCallback(
290
+ this.keyManager
291
+ )
292
+
293
+ signCallback: (kid: string, value: string) => Promise<string> = defaultOydCmsmSignCallback(this.keyManager)
294
+ }
@@ -1,19 +1,40 @@
1
+ import { IKey, TKeyType } from '@veramo/core'
2
+
3
+ export type OydConstructorOptions = {
4
+ defaultKms?: string;
5
+ clientManagedSecretMode?: CMSMCallbackOpts;
6
+ }
7
+
1
8
  export type OydCreateIdentifierOptions = {
2
- keyType?: OydDidSupportedKeyTypes
3
- privateKeyHex?: string
4
- keyUse?: KeyUse
9
+ keyType?: OydDidSupportedKeyTypes;
10
+ privateKeyHex?: string;
11
+ kid?: string;
12
+ keyUse?: KeyUse;
13
+ cmsm?: CmsmOptions;
14
+ key?: IKey // Use the supplied key instead of looking it up in the KMS or creating a new one
15
+ }
16
+
17
+
18
+ export type CmsmOptions = {
19
+ enabled: boolean
20
+ create?: boolean
5
21
  }
6
22
 
7
23
  export type OydDidHoldKeysArgs = {
8
- kms: string
9
- options: HoldKeysOpts
24
+ kms?: string;
25
+ options: HoldKeysOpts;
10
26
  }
11
27
 
12
28
  type HoldKeysOpts = {
13
- keyType: OydDidSupportedKeyTypes
14
- kid: string
15
- publicKeyHex?: string
16
- privateKeyHex?: string
29
+ keyType: OydDidSupportedKeyTypes;
30
+ kid: string;
31
+ publicKeyHex?: string;
32
+ privateKeyHex?: string;
33
+ }
34
+
35
+ export type CMSMCallbackOpts = {
36
+ publicKeyCallback: (kid: string, kms?: string, create?: boolean, createKeyType?: TKeyType) => Promise<IKey>;
37
+ signCallback: (kid: string, value: string) => Promise<string>;
17
38
  }
18
39
 
19
40
  export enum SupportedKeyTypes {
@@ -23,6 +44,6 @@ export enum SupportedKeyTypes {
23
44
  X25519 = 'X25519',
24
45
  }
25
46
 
26
- export type OydDidSupportedKeyTypes = keyof typeof SupportedKeyTypes
47
+ export type OydDidSupportedKeyTypes = keyof typeof SupportedKeyTypes;
27
48
 
28
- export type KeyUse = 'sig' | 'enc'
49
+ export type KeyUse = 'sig' | 'enc';
package/dist/index.cjs DELETED
@@ -1,193 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/index.ts
32
- var index_exports = {};
33
- __export(index_exports, {
34
- OydDIDProvider: () => OydDIDProvider,
35
- SupportedKeyTypes: () => SupportedKeyTypes,
36
- getDidOydResolver: () => getDidOydResolver
37
- });
38
- module.exports = __toCommonJS(index_exports);
39
-
40
- // src/oyd-did-provider.ts
41
- var import_did_manager = require("@veramo/did-manager");
42
- var import_cross_fetch = __toESM(require("cross-fetch"), 1);
43
- var import_debug = __toESM(require("debug"), 1);
44
- var debug = (0, import_debug.default)("veramo:oyd-did:identifier-provider");
45
- var OydDIDProvider = class extends import_did_manager.AbstractIdentifierProvider {
46
- static {
47
- __name(this, "OydDIDProvider");
48
- }
49
- defaultKms;
50
- constructor(options) {
51
- super();
52
- this.defaultKms = options.defaultKms;
53
- }
54
- async createIdentifier({ kms, options }, context) {
55
- const body = {
56
- options
57
- };
58
- const url = "https://oydid-registrar.data-container.net/1.0/createIdentifier";
59
- let didDoc;
60
- try {
61
- const response = await (0, import_cross_fetch.default)(url, {
62
- method: "POST",
63
- headers: {
64
- "Content-Type": "application/json"
65
- },
66
- body: JSON.stringify(body)
67
- });
68
- if (!response.ok) {
69
- throw new Error("Network response was not ok: " + response.statusText);
70
- }
71
- didDoc = await response.json();
72
- } catch (error) {
73
- throw new Error("There has been a problem with the fetch operation: " + error.toString());
74
- }
75
- const keyType = options?.keyType || "Ed25519";
76
- const key = await this.holdKeys({
77
- // @ts-ignore
78
- kms: kms || this.defaultKms,
79
- options: {
80
- keyType,
81
- kid: didDoc.did + "#key-doc",
82
- publicKeyHex: didDoc.keys[0].publicKeyHex,
83
- privateKeyHex: didDoc.keys[0].privateKeyHex
84
- }
85
- }, context);
86
- const identifier = {
87
- did: didDoc.did,
88
- controllerKeyId: key.kid,
89
- keys: [
90
- key
91
- ],
92
- services: []
93
- };
94
- debug("Created", identifier.did);
95
- return identifier;
96
- }
97
- async updateIdentifier(args, context) {
98
- throw new Error("OydDIDProvider updateIdentifier not supported yet.");
99
- }
100
- async deleteIdentifier(identifier, context) {
101
- for (const { kid } of identifier.keys) {
102
- await context.agent.keyManagerDelete({
103
- kid
104
- });
105
- }
106
- return true;
107
- }
108
- async addKey({ identifier, key, options }, context) {
109
- return {
110
- success: true
111
- };
112
- }
113
- async addService({ identifier, service, options }, context) {
114
- return {
115
- success: true
116
- };
117
- }
118
- async removeKey(args, context) {
119
- return {
120
- success: true
121
- };
122
- }
123
- async removeService(args, context) {
124
- return {
125
- success: true
126
- };
127
- }
128
- async holdKeys(args, context) {
129
- if (args.options.privateKeyHex) {
130
- return context.agent.keyManagerImport({
131
- // @ts-ignore
132
- kms: args.kms || this.defaultKms,
133
- type: args.options.keyType,
134
- kid: args.options.kid,
135
- privateKeyHex: args.options.privateKeyHex,
136
- meta: {
137
- algorithms: [
138
- "Ed25519"
139
- ]
140
- }
141
- });
142
- }
143
- return context.agent.keyManagerCreate({
144
- type: args.options.keyType,
145
- // @ts-ignore
146
- kms: args.kms || this.defaultKms,
147
- meta: {
148
- algorithms: [
149
- "Ed25519"
150
- ]
151
- }
152
- });
153
- }
154
- };
155
-
156
- // src/resolver.ts
157
- var import_cross_fetch2 = __toESM(require("cross-fetch"), 1);
158
- var resolveDidOyd = /* @__PURE__ */ __name(async (didUrl, _parsed, _resolver, options) => {
159
- try {
160
- const baseUrl = "https://oydid-resolver.data-container.net";
161
- const response = await (0, import_cross_fetch2.default)(`${baseUrl}/1.0/identifiers/${didUrl}`);
162
- if (!response.ok) {
163
- throw new Error("Network response was not ok: " + response.statusText);
164
- }
165
- const didDoc = await response.json();
166
- return didDoc;
167
- } catch (err) {
168
- return {
169
- didDocumentMetadata: {},
170
- didResolutionMetadata: {
171
- error: "invalidDid",
172
- message: err.toString()
173
- },
174
- didDocument: null
175
- };
176
- }
177
- }, "resolveDidOyd");
178
- function getDidOydResolver() {
179
- return {
180
- oyd: resolveDidOyd
181
- };
182
- }
183
- __name(getDidOydResolver, "getDidOydResolver");
184
-
185
- // src/types/oyd-provider-types.ts
186
- var SupportedKeyTypes = /* @__PURE__ */ function(SupportedKeyTypes2) {
187
- SupportedKeyTypes2["Secp256r1"] = "Secp256r1";
188
- SupportedKeyTypes2["Secp256k1"] = "Secp256k1";
189
- SupportedKeyTypes2["Ed25519"] = "Ed25519";
190
- SupportedKeyTypes2["X25519"] = "X25519";
191
- return SupportedKeyTypes2;
192
- }({});
193
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/oyd-did-provider.ts","../src/resolver.ts","../src/types/oyd-provider-types.ts"],"sourcesContent":["/**\n * Provides `did:oyd` {@link @ownyourdata/did-provider-oyd#OydDIDProvider | identifier provider } for the\n * {@link @veramo/did-manager#DIDManager}\n *\n * @packageDocumentation\n */\nexport { OydDIDProvider } from './oyd-did-provider.js'\nexport { getDidOydResolver } from './resolver.js'\nexport * from './types/oyd-provider-types.js'\n","import { IIdentifier, IKey, IService, IAgentContext, IKeyManager } from '@veramo/core'\nimport { AbstractIdentifierProvider } from '@veramo/did-manager'\nimport type { OydCreateIdentifierOptions, OydDidHoldKeysArgs, OydDidSupportedKeyTypes } from './types/oyd-provider-types.js'\nimport fetch from 'cross-fetch'\n\nimport Debug from 'debug'\nconst debug = Debug('veramo:oyd-did:identifier-provider')\n\ntype IContext = IAgentContext<IKeyManager>\n\n/**\n * {@link @veramo/did-manager#DIDManager} identifier provider for `did:oyd` identifiers\n * @public\n */\nexport class OydDIDProvider extends AbstractIdentifierProvider {\n private defaultKms?: string\n\n constructor(options: { defaultKms?: string }) {\n super()\n this.defaultKms = options.defaultKms\n }\n\n async createIdentifier(\n { kms, options }: { kms?: string; options: OydCreateIdentifierOptions },\n context: IContext\n ): Promise<Omit<IIdentifier, 'provider'>> {\n const body = { options }\n const url = 'https://oydid-registrar.data-container.net/1.0/createIdentifier'\n\n let didDoc: any | undefined\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n })\n if (!response.ok) {\n throw new Error('Network response was not ok: ' + response.statusText)\n }\n didDoc = await response.json()\n } catch (error) {\n // @ts-ignore\n throw new Error('There has been a problem with the fetch operation: ' + error.toString())\n }\n\n const keyType: OydDidSupportedKeyTypes = options?.keyType || 'Ed25519'\n const key = await this.holdKeys(\n {\n // @ts-ignore\n kms: kms || this.defaultKms,\n options: {\n keyType,\n kid: didDoc.did + '#key-doc',\n publicKeyHex: didDoc.keys[0].publicKeyHex,\n privateKeyHex: didDoc.keys[0].privateKeyHex,\n },\n },\n context\n )\n\n const identifier: Omit<IIdentifier, 'provider'> = {\n did: didDoc.did,\n controllerKeyId: key.kid,\n keys: [key],\n services: [],\n }\n debug('Created', identifier.did)\n return identifier\n }\n\n async updateIdentifier(\n args: { did: string; kms?: string | undefined; alias?: string | undefined; options?: any },\n context: IAgentContext<IKeyManager>\n ): Promise<IIdentifier> {\n throw new Error('OydDIDProvider updateIdentifier not supported yet.')\n }\n\n async deleteIdentifier(identifier: IIdentifier, context: IContext): Promise<boolean> {\n for (const { kid } of identifier.keys) {\n await context.agent.keyManagerDelete({ kid })\n }\n return true\n }\n\n async addKey({ identifier, key, options }: { identifier: IIdentifier; key: IKey; options?: any }, context: IContext): Promise<any> {\n return { success: true }\n }\n\n async addService({ identifier, service, options }: { identifier: IIdentifier; service: IService; options?: any }, context: IContext): Promise<any> {\n return { success: true }\n }\n\n async removeKey(args: { identifier: IIdentifier; kid: string; options?: any }, context: IContext): Promise<any> {\n return { success: true }\n }\n\n async removeService(args: { identifier: IIdentifier; id: string; options?: any }, context: IContext): Promise<any> {\n return { success: true }\n }\n\n private async holdKeys(args: OydDidHoldKeysArgs, context: IContext): Promise<IKey> {\n if (args.options.privateKeyHex) {\n return context.agent.keyManagerImport({\n // @ts-ignore\n kms: args.kms || this.defaultKms,\n type: args.options.keyType,\n kid: args.options.kid,\n privateKeyHex: args.options.privateKeyHex,\n meta: {\n algorithms: ['Ed25519'],\n },\n })\n }\n return context.agent.keyManagerCreate({\n type: args.options.keyType,\n // @ts-ignore\n kms: args.kms || this.defaultKms,\n meta: {\n algorithms: ['Ed25519'],\n },\n })\n }\n}\n","import { DIDResolutionOptions, DIDResolutionResult, DIDResolver, ParsedDID, Resolvable } from 'did-resolver'\nimport fetch from 'cross-fetch'\n\nconst resolveDidOyd: DIDResolver = async (\n didUrl: string,\n _parsed: ParsedDID,\n _resolver: Resolvable,\n options: DIDResolutionOptions\n): Promise<DIDResolutionResult> => {\n try {\n const baseUrl: string = 'https://oydid-resolver.data-container.net'\n // const didDoc = await axios.get(`${baseUrl}/1.0/identifiers/${didUrl}`);\n const response = await fetch(`${baseUrl}/1.0/identifiers/${didUrl}`)\n if (!response.ok) {\n throw new Error('Network response was not ok: ' + response.statusText)\n }\n const didDoc = await response.json()\n return didDoc as DIDResolutionResult\n } catch (err: any) {\n return {\n didDocumentMetadata: {},\n didResolutionMetadata: { error: 'invalidDid', message: err.toString() },\n didDocument: null,\n }\n }\n}\n\n/**\n * Provides a mapping to a did:oyd resolver, usable by {@link did-resolver#Resolver}.\n *\n * @public\n */\nexport function getDidOydResolver() {\n return { oyd: resolveDidOyd }\n}\n","export type OydCreateIdentifierOptions = {\n keyType?: OydDidSupportedKeyTypes\n privateKeyHex?: string\n keyUse?: KeyUse\n}\n\nexport type OydDidHoldKeysArgs = {\n kms: string\n options: HoldKeysOpts\n}\n\ntype HoldKeysOpts = {\n keyType: OydDidSupportedKeyTypes\n kid: string\n publicKeyHex?: string\n privateKeyHex?: string\n}\n\nexport enum SupportedKeyTypes {\n Secp256r1 = 'Secp256r1',\n Secp256k1 = 'Secp256k1',\n Ed25519 = 'Ed25519',\n X25519 = 'X25519',\n}\n\nexport type OydDidSupportedKeyTypes = keyof typeof SupportedKeyTypes\n\nexport type KeyUse = 'sig' | 'enc'\n"],"mappings":"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","names":["debug","Debug","OydDIDProvider","AbstractIdentifierProvider","defaultKms","constructor","options","createIdentifier","kms","context","body","url","didDoc","response","fetch","method","headers","JSON","stringify","ok","Error","statusText","json","error","toString","keyType","key","holdKeys","kid","did","publicKeyHex","keys","privateKeyHex","identifier","controllerKeyId","services","updateIdentifier","args","deleteIdentifier","agent","keyManagerDelete","addKey","success","addService","service","removeKey","removeService","keyManagerImport","type","meta","algorithms","keyManagerCreate","import_cross_fetch","resolveDidOyd","didUrl","_parsed","_resolver","options","baseUrl","response","fetch","ok","Error","statusText","didDoc","json","err","didDocumentMetadata","didResolutionMetadata","error","message","toString","didDocument","getDidOydResolver","oyd","SupportedKeyTypes"]}
package/dist/index.d.cts DELETED
@@ -1,82 +0,0 @@
1
- import { IAgentContext, IKeyManager, IIdentifier, IKey, IService } from '@veramo/core';
2
- import { AbstractIdentifierProvider } from '@veramo/did-manager';
3
- import { DIDResolver } from 'did-resolver';
4
-
5
- type OydCreateIdentifierOptions = {
6
- keyType?: OydDidSupportedKeyTypes;
7
- privateKeyHex?: string;
8
- keyUse?: KeyUse;
9
- };
10
- type OydDidHoldKeysArgs = {
11
- kms: string;
12
- options: HoldKeysOpts;
13
- };
14
- type HoldKeysOpts = {
15
- keyType: OydDidSupportedKeyTypes;
16
- kid: string;
17
- publicKeyHex?: string;
18
- privateKeyHex?: string;
19
- };
20
- declare enum SupportedKeyTypes {
21
- Secp256r1 = "Secp256r1",
22
- Secp256k1 = "Secp256k1",
23
- Ed25519 = "Ed25519",
24
- X25519 = "X25519"
25
- }
26
- type OydDidSupportedKeyTypes = keyof typeof SupportedKeyTypes;
27
- type KeyUse = 'sig' | 'enc';
28
-
29
- type IContext = IAgentContext<IKeyManager>;
30
- /**
31
- * {@link @veramo/did-manager#DIDManager} identifier provider for `did:oyd` identifiers
32
- * @public
33
- */
34
- declare class OydDIDProvider extends AbstractIdentifierProvider {
35
- private defaultKms?;
36
- constructor(options: {
37
- defaultKms?: string;
38
- });
39
- createIdentifier({ kms, options }: {
40
- kms?: string;
41
- options: OydCreateIdentifierOptions;
42
- }, context: IContext): Promise<Omit<IIdentifier, 'provider'>>;
43
- updateIdentifier(args: {
44
- did: string;
45
- kms?: string | undefined;
46
- alias?: string | undefined;
47
- options?: any;
48
- }, context: IAgentContext<IKeyManager>): Promise<IIdentifier>;
49
- deleteIdentifier(identifier: IIdentifier, context: IContext): Promise<boolean>;
50
- addKey({ identifier, key, options }: {
51
- identifier: IIdentifier;
52
- key: IKey;
53
- options?: any;
54
- }, context: IContext): Promise<any>;
55
- addService({ identifier, service, options }: {
56
- identifier: IIdentifier;
57
- service: IService;
58
- options?: any;
59
- }, context: IContext): Promise<any>;
60
- removeKey(args: {
61
- identifier: IIdentifier;
62
- kid: string;
63
- options?: any;
64
- }, context: IContext): Promise<any>;
65
- removeService(args: {
66
- identifier: IIdentifier;
67
- id: string;
68
- options?: any;
69
- }, context: IContext): Promise<any>;
70
- private holdKeys;
71
- }
72
-
73
- /**
74
- * Provides a mapping to a did:oyd resolver, usable by {@link did-resolver#Resolver}.
75
- *
76
- * @public
77
- */
78
- declare function getDidOydResolver(): {
79
- oyd: DIDResolver;
80
- };
81
-
82
- export { type KeyUse, type OydCreateIdentifierOptions, OydDIDProvider, type OydDidHoldKeysArgs, type OydDidSupportedKeyTypes, SupportedKeyTypes, getDidOydResolver };