@sphereon/did-provider-oyd 0.28.1-feature.jose.vcdm.52 → 0.28.1-feature.oyd.cmsm.improv.20
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/README.md +10 -10
- package/dist/index.d.ts +7 -108
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -323
- package/dist/index.js.map +1 -1
- package/dist/oyd-did-provider.d.ts +61 -0
- package/dist/oyd-did-provider.d.ts.map +1 -0
- package/dist/oyd-did-provider.js +330 -0
- package/dist/oyd-did-provider.js.map +1 -0
- package/dist/resolver.d.ts +10 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +44 -0
- package/dist/resolver.js.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/types/oyd-provider-types.d.ts +41 -0
- package/dist/types/oyd-provider-types.d.ts.map +1 -0
- package/dist/types/oyd-provider-types.js +11 -0
- package/dist/types/oyd-provider-types.js.map +1 -0
- package/package.json +17 -26
- package/src/index.ts +2 -2
- package/src/oyd-did-provider.ts +69 -52
- package/src/types/oyd-provider-types.ts +19 -19
- package/dist/index.cjs +0 -356
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -111
package/src/oyd-did-provider.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { importProvidedOrGeneratedKey } from '@sphereon/ssi-sdk-ext.key-utils'
|
|
2
1
|
import { IAgentContext, IIdentifier, IKey, IKeyManager, IService, TKeyType } from '@veramo/core'
|
|
3
2
|
import { AbstractIdentifierProvider } from '@veramo/did-manager'
|
|
4
3
|
import { KeyManager } from '@veramo/key-manager'
|
|
@@ -6,7 +5,6 @@ import fetch from 'cross-fetch'
|
|
|
6
5
|
import Multibase from 'multibase'
|
|
7
6
|
import Multicodec from 'multicodec'
|
|
8
7
|
|
|
9
|
-
// @ts-ignore
|
|
10
8
|
import * as u8a from 'uint8arrays'
|
|
11
9
|
|
|
12
10
|
import Debug from 'debug'
|
|
@@ -14,9 +12,9 @@ import type {
|
|
|
14
12
|
CMSMCallbackOpts,
|
|
15
13
|
OydConstructorOptions,
|
|
16
14
|
OydCreateIdentifierOptions,
|
|
17
|
-
|
|
15
|
+
OydDidHoldKeysArgs,
|
|
18
16
|
OydDidSupportedKeyTypes,
|
|
19
|
-
} from './types/oyd-provider-types'
|
|
17
|
+
} from './types/oyd-provider-types.js'
|
|
20
18
|
|
|
21
19
|
const debug = Debug('veramo:oyd-did:identifier-provider')
|
|
22
20
|
const OYDID_REGISTRAR_URL = 'https://oydid-registrar.data-container.net/1.0/createIdentifier'
|
|
@@ -49,7 +47,7 @@ export class OydDIDProvider extends AbstractIdentifierProvider {
|
|
|
49
47
|
}
|
|
50
48
|
|
|
51
49
|
async createIdentifier(
|
|
52
|
-
{ kms,
|
|
50
|
+
{ kms, options }: { kms?: string; options: OydCreateIdentifierOptions },
|
|
53
51
|
context: IContext
|
|
54
52
|
): Promise<Omit<IIdentifier, 'provider'>> {
|
|
55
53
|
const resolvedKms = await this.assertedKms(kms, this.defaultKms)
|
|
@@ -64,7 +62,7 @@ export class OydDIDProvider extends AbstractIdentifierProvider {
|
|
|
64
62
|
const body = {
|
|
65
63
|
options: {
|
|
66
64
|
cmsm: false,
|
|
67
|
-
key_type: options.
|
|
65
|
+
key_type: options.keyType ?? 'Secp256r1',
|
|
68
66
|
},
|
|
69
67
|
}
|
|
70
68
|
let didDoc: any | undefined
|
|
@@ -86,18 +84,15 @@ export class OydDIDProvider extends AbstractIdentifierProvider {
|
|
|
86
84
|
return Promise.reject(Error('There has been a problem with the fetch operation: ' + error.toString()))
|
|
87
85
|
}
|
|
88
86
|
|
|
89
|
-
const keyType: OydDidSupportedKeyTypes = options?.
|
|
90
|
-
const key = await
|
|
87
|
+
const keyType: OydDidSupportedKeyTypes = options?.keyType ?? 'Secp256r1'
|
|
88
|
+
const key = await this.importOrCreateKey(
|
|
91
89
|
{
|
|
92
90
|
kms: resolvedKms,
|
|
93
|
-
alias: alias ?? options.alias ?? options.kid ?? `${didDoc.did}#key-doc`,
|
|
94
91
|
options: {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
privateKeyHex: didDoc.keys[0].privateKeyHex,
|
|
100
|
-
},
|
|
92
|
+
keyType,
|
|
93
|
+
kid: didDoc.did + '#key-doc',
|
|
94
|
+
publicKeyHex: didDoc.keys[0].publicKeyHex,
|
|
95
|
+
privateKeyHex: didDoc.keys[0].privateKeyHex,
|
|
101
96
|
},
|
|
102
97
|
},
|
|
103
98
|
context
|
|
@@ -124,10 +119,11 @@ export class OydDIDProvider extends AbstractIdentifierProvider {
|
|
|
124
119
|
|
|
125
120
|
const assertedKms = await this.assertedKms(kms, this.defaultKms)
|
|
126
121
|
const pubKey =
|
|
127
|
-
options.key ??
|
|
122
|
+
options.key ??
|
|
123
|
+
(await cmsmCallbackOpts.publicKeyCallback(options.kid ?? 'default', assertedKms, options.cmsm?.create !== false, options.keyType)) // "default" is probably not right, TODO!!
|
|
128
124
|
const kid = pubKey.kid
|
|
129
125
|
const keyType = pubKey.type
|
|
130
|
-
const key = base58btc({
|
|
126
|
+
const key = base58btc({publicKeyHex: pubKey.publicKeyHex, keyType})
|
|
131
127
|
|
|
132
128
|
console.log(`Bae58 pubkey key: ${key}`)
|
|
133
129
|
let signValue: any | undefined // do the request
|
|
@@ -165,6 +161,8 @@ export class OydDIDProvider extends AbstractIdentifierProvider {
|
|
|
165
161
|
|
|
166
162
|
console.log(`Signature: ${signature}`)
|
|
167
163
|
|
|
164
|
+
|
|
165
|
+
|
|
168
166
|
const body_signed = {
|
|
169
167
|
key,
|
|
170
168
|
options: {
|
|
@@ -197,6 +195,24 @@ export class OydDIDProvider extends AbstractIdentifierProvider {
|
|
|
197
195
|
return Promise.reject(Error('There has been a problem with the fetch operation: ' + error.toString()))
|
|
198
196
|
}
|
|
199
197
|
|
|
198
|
+
/* let oydKeyType: OydDidSupportedKeyTypes = "Secp256r1";
|
|
199
|
+
|
|
200
|
+
const key = await this.holdKeys(
|
|
201
|
+
{
|
|
202
|
+
kms: assertedKms,
|
|
203
|
+
options: {
|
|
204
|
+
keyType: oydKeyType,
|
|
205
|
+
kid: kid,
|
|
206
|
+
publicKeyHex: pubKey.publicKeyHex,
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
context
|
|
210
|
+
);*/
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
200
216
|
const identifier: Omit<IIdentifier, 'provider'> = {
|
|
201
217
|
did: didDoc.did,
|
|
202
218
|
controllerKeyId: pubKey.kid,
|
|
@@ -236,6 +252,31 @@ export class OydDIDProvider extends AbstractIdentifierProvider {
|
|
|
236
252
|
async removeService(args: { identifier: IIdentifier; id: string; options?: any }, context: IContext): Promise<any> {
|
|
237
253
|
return { success: true }
|
|
238
254
|
}
|
|
255
|
+
|
|
256
|
+
private async importOrCreateKey(args: OydDidHoldKeysArgs, context: IContext): Promise<IKey> {
|
|
257
|
+
const kms = await this.assertedKms(args.kms, this.defaultKms)
|
|
258
|
+
if (args.options.privateKeyHex) {
|
|
259
|
+
return context.agent.keyManagerImport({
|
|
260
|
+
kms,
|
|
261
|
+
type: args.options.keyType,
|
|
262
|
+
kid: args.options.kid,
|
|
263
|
+
privateKeyHex: args.options.privateKeyHex,
|
|
264
|
+
/*meta: {
|
|
265
|
+
algorithms: ['Secp256r1'],
|
|
266
|
+
},*/
|
|
267
|
+
})
|
|
268
|
+
}
|
|
269
|
+
return context.agent.keyManagerCreate({
|
|
270
|
+
type: args.options.keyType,
|
|
271
|
+
kms,
|
|
272
|
+
meta: {
|
|
273
|
+
algorithms: ['Secp256r1'],
|
|
274
|
+
},
|
|
275
|
+
})
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
239
280
|
}
|
|
240
281
|
|
|
241
282
|
const keyCodecs = {
|
|
@@ -248,15 +289,17 @@ const keyCodecs = {
|
|
|
248
289
|
Bls12381G2: 'bls12_381-g2-pub',
|
|
249
290
|
} as const
|
|
250
291
|
|
|
251
|
-
const base58btc = ({
|
|
292
|
+
const base58btc = ({publicKeyHex, keyType = 'Secp256r1'}:{publicKeyHex: string, keyType?: TKeyType}): string => {
|
|
252
293
|
const codecName = keyCodecs[keyType]
|
|
253
294
|
|
|
295
|
+
|
|
254
296
|
// methodSpecificId = bytesToMultibase({bytes: u8a.fromString(key.publicKeyHex, 'hex'), codecName})
|
|
255
297
|
return u8a
|
|
256
|
-
.toString(
|
|
298
|
+
.toString(
|
|
299
|
+
Multibase.encode('base58btc', Multicodec.addPrefix(codecName as Multicodec.CodecName, u8a.fromString(publicKeyHex, 'hex')))
|
|
300
|
+
)
|
|
257
301
|
.toString()
|
|
258
302
|
}
|
|
259
|
-
|
|
260
303
|
export function defaultOydCmsmPublicKeyCallback(
|
|
261
304
|
keyManager: KeyManager
|
|
262
305
|
): (kid: string, kms?: string, create?: boolean, createKeyType?: TKeyType) => Promise<IKey> {
|
|
@@ -271,27 +314,7 @@ export function defaultOydCmsmPublicKeyCallback(
|
|
|
271
314
|
if (!kms) {
|
|
272
315
|
return Promise.reject(Error('No KMS provided, whilst creating a new key!'))
|
|
273
316
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const agent = keyManager
|
|
277
|
-
const key = await importProvidedOrGeneratedKey(
|
|
278
|
-
{
|
|
279
|
-
kms,
|
|
280
|
-
alias,
|
|
281
|
-
options: {
|
|
282
|
-
key: {
|
|
283
|
-
type: createKeyType ?? 'Secp256r1',
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
//@ts-ignore
|
|
289
|
-
agent,
|
|
290
|
-
}
|
|
291
|
-
)
|
|
292
|
-
return key
|
|
293
|
-
|
|
294
|
-
// return await keyManager.keyManagerCreate({ kms, type: createKeyType ?? 'Secp256r1' })
|
|
317
|
+
return await keyManager.keyManagerCreate({ kms, type: createKeyType ?? 'Secp256r1' })
|
|
295
318
|
}
|
|
296
319
|
return Promise.reject(Error('No existing key found, and create is false!'))
|
|
297
320
|
}
|
|
@@ -304,17 +327,11 @@ export function defaultOydCmsmSignCallback(keyManager: KeyManager): (kid: string
|
|
|
304
327
|
}
|
|
305
328
|
|
|
306
329
|
export class DefaultOydCmsmCallbacks implements CMSMCallbackOpts {
|
|
307
|
-
private
|
|
330
|
+
constructor(private keyManager: KeyManager) {}
|
|
308
331
|
|
|
309
|
-
|
|
310
|
-
this.keyManager
|
|
311
|
-
|
|
332
|
+
publicKeyCallback: (kid: string, kms?: string, create?: boolean, createKeyType?: TKeyType) => Promise<IKey> = defaultOydCmsmPublicKeyCallback(
|
|
333
|
+
this.keyManager
|
|
334
|
+
)
|
|
312
335
|
|
|
313
|
-
|
|
314
|
-
return defaultOydCmsmPublicKeyCallback(this.keyManager)(kid, kms, create, createKeyType)
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
signCallback(kid: string, value: string): Promise<string> {
|
|
318
|
-
return defaultOydCmsmSignCallback(this.keyManager)(kid, value)
|
|
319
|
-
}
|
|
336
|
+
signCallback: (kid: string, value: string) => Promise<string> = defaultOydCmsmSignCallback(this.keyManager)
|
|
320
337
|
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
import { IKey, TKeyType } from '@veramo/core'
|
|
2
2
|
|
|
3
3
|
export type OydConstructorOptions = {
|
|
4
|
-
defaultKms?: string
|
|
5
|
-
clientManagedSecretMode?: CMSMCallbackOpts
|
|
4
|
+
defaultKms?: string;
|
|
5
|
+
clientManagedSecretMode?: CMSMCallbackOpts;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export type OydCreateIdentifierOptions = {
|
|
9
|
-
|
|
10
|
-
privateKeyHex?: string
|
|
11
|
-
kid?: string
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
cmsm?: CmsmOptions
|
|
9
|
+
keyType?: OydDidSupportedKeyTypes;
|
|
10
|
+
privateKeyHex?: string;
|
|
11
|
+
kid?: string;
|
|
12
|
+
keyUse?: KeyUse;
|
|
13
|
+
cmsm?: CmsmOptions;
|
|
15
14
|
key?: IKey // Use the supplied key instead of looking it up in the KMS or creating a new one
|
|
16
15
|
}
|
|
17
16
|
|
|
17
|
+
|
|
18
18
|
export type CmsmOptions = {
|
|
19
19
|
enabled: boolean
|
|
20
20
|
create?: boolean
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export type OydDidHoldKeysArgs = {
|
|
24
|
-
kms?: string
|
|
25
|
-
options: HoldKeysOpts
|
|
24
|
+
kms?: string;
|
|
25
|
+
options: HoldKeysOpts;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
type HoldKeysOpts = {
|
|
29
|
-
keyType: OydDidSupportedKeyTypes
|
|
30
|
-
kid: string
|
|
31
|
-
publicKeyHex?: string
|
|
32
|
-
privateKeyHex?: string
|
|
29
|
+
keyType: OydDidSupportedKeyTypes;
|
|
30
|
+
kid: string;
|
|
31
|
+
publicKeyHex?: string;
|
|
32
|
+
privateKeyHex?: string;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export type CMSMCallbackOpts = {
|
|
36
|
-
publicKeyCallback: (kid: string, kms?: string, create?: boolean, createKeyType?: TKeyType) => Promise<IKey
|
|
37
|
-
signCallback: (kid: string, value: string) => Promise<string
|
|
36
|
+
publicKeyCallback: (kid: string, kms?: string, create?: boolean, createKeyType?: TKeyType) => Promise<IKey>;
|
|
37
|
+
signCallback: (kid: string, value: string) => Promise<string>;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
enum SupportedKeyTypes {
|
|
40
|
+
export enum SupportedKeyTypes {
|
|
41
41
|
Secp256r1 = 'Secp256r1',
|
|
42
42
|
Secp256k1 = 'Secp256k1',
|
|
43
43
|
Ed25519 = 'Ed25519',
|
|
44
44
|
X25519 = 'X25519',
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export type OydDidSupportedKeyTypes = keyof typeof SupportedKeyTypes
|
|
47
|
+
export type OydDidSupportedKeyTypes = keyof typeof SupportedKeyTypes;
|
|
48
48
|
|
|
49
|
-
export type KeyUse = 'sig' | 'enc'
|
|
49
|
+
export type KeyUse = 'sig' | 'enc';
|
package/dist/index.cjs
DELETED
|
@@ -1,356 +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
|
-
DefaultOydCmsmCallbacks: () => DefaultOydCmsmCallbacks,
|
|
35
|
-
OydDIDProvider: () => OydDIDProvider,
|
|
36
|
-
defaultOydCmsmPublicKeyCallback: () => defaultOydCmsmPublicKeyCallback,
|
|
37
|
-
defaultOydCmsmSignCallback: () => defaultOydCmsmSignCallback,
|
|
38
|
-
getDidOydResolver: () => getDidOydResolver
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(index_exports);
|
|
41
|
-
|
|
42
|
-
// src/oyd-did-provider.ts
|
|
43
|
-
var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
44
|
-
var import_did_manager = require("@veramo/did-manager");
|
|
45
|
-
var import_cross_fetch = __toESM(require("cross-fetch"), 1);
|
|
46
|
-
var import_multibase = __toESM(require("multibase"), 1);
|
|
47
|
-
var import_multicodec = __toESM(require("multicodec"), 1);
|
|
48
|
-
var u8a = __toESM(require("uint8arrays"), 1);
|
|
49
|
-
var import_debug = __toESM(require("debug"), 1);
|
|
50
|
-
var debug = (0, import_debug.default)("veramo:oyd-did:identifier-provider");
|
|
51
|
-
var OYDID_REGISTRAR_URL = "https://oydid-registrar.data-container.net/1.0/createIdentifier";
|
|
52
|
-
var OydDIDProvider = class extends import_did_manager.AbstractIdentifierProvider {
|
|
53
|
-
static {
|
|
54
|
-
__name(this, "OydDIDProvider");
|
|
55
|
-
}
|
|
56
|
-
defaultKms;
|
|
57
|
-
cmsmCallbackOpts;
|
|
58
|
-
constructor(options) {
|
|
59
|
-
super();
|
|
60
|
-
this.defaultKms = options?.defaultKms;
|
|
61
|
-
this.cmsmCallbackOpts = options?.clientManagedSecretMode;
|
|
62
|
-
}
|
|
63
|
-
async assertedKms(...kms) {
|
|
64
|
-
if (!kms || kms.length === 0) {
|
|
65
|
-
return Promise.reject(Error("KMS must be provided either as a parameter or via defaultKms."));
|
|
66
|
-
}
|
|
67
|
-
const result = kms.find((k) => !!k);
|
|
68
|
-
if (!result) {
|
|
69
|
-
return Promise.reject(Error("KMS must be provided either as a parameter or via defaultKms."));
|
|
70
|
-
}
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
async createIdentifier({ kms, alias, options }, context) {
|
|
74
|
-
const resolvedKms = await this.assertedKms(kms, this.defaultKms);
|
|
75
|
-
if (this.cmsmCallbackOpts && !options.cmsm || options.cmsm && options.cmsm.enabled !== false) {
|
|
76
|
-
if (!this.cmsmCallbackOpts) {
|
|
77
|
-
return Promise.reject(Error("did:oyd: no cmsm options defined on oyd did provider, but cmsm was enabled on the call!"));
|
|
78
|
-
}
|
|
79
|
-
return await this.createIdentifierWithCMSM({
|
|
80
|
-
kms: resolvedKms,
|
|
81
|
-
options
|
|
82
|
-
}, context);
|
|
83
|
-
}
|
|
84
|
-
const body = {
|
|
85
|
-
options: {
|
|
86
|
-
cmsm: false,
|
|
87
|
-
key_type: options.type ?? "Secp256r1"
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
let didDoc;
|
|
91
|
-
try {
|
|
92
|
-
const response = await (0, import_cross_fetch.default)(OYDID_REGISTRAR_URL, {
|
|
93
|
-
method: "POST",
|
|
94
|
-
headers: {
|
|
95
|
-
"Content-Type": "application/json"
|
|
96
|
-
},
|
|
97
|
-
body: JSON.stringify(body)
|
|
98
|
-
});
|
|
99
|
-
if (!response.ok) {
|
|
100
|
-
debug("Error response from OydDID Registrar: ", response);
|
|
101
|
-
return Promise.reject(Error("Network response was not ok: " + response.statusText));
|
|
102
|
-
}
|
|
103
|
-
didDoc = await response.json();
|
|
104
|
-
} catch (error) {
|
|
105
|
-
debug("Unexpected error from OydDID Registrar: ", error);
|
|
106
|
-
return Promise.reject(Error("There has been a problem with the fetch operation: " + error.toString()));
|
|
107
|
-
}
|
|
108
|
-
const keyType = options?.type ?? "Secp256r1";
|
|
109
|
-
const key = await (0, import_ssi_sdk_ext.importProvidedOrGeneratedKey)({
|
|
110
|
-
kms: resolvedKms,
|
|
111
|
-
alias: alias ?? options.alias ?? options.kid ?? `${didDoc.did}#key-doc`,
|
|
112
|
-
options: {
|
|
113
|
-
key: {
|
|
114
|
-
kid: `${didDoc.did}#key-doc`,
|
|
115
|
-
type: keyType,
|
|
116
|
-
publicKeyHex: didDoc.keys[0].publicKeyHex,
|
|
117
|
-
privateKeyHex: didDoc.keys[0].privateKeyHex
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}, context);
|
|
121
|
-
const identifier = {
|
|
122
|
-
did: didDoc.did,
|
|
123
|
-
controllerKeyId: key.kid,
|
|
124
|
-
keys: [
|
|
125
|
-
key
|
|
126
|
-
],
|
|
127
|
-
services: []
|
|
128
|
-
};
|
|
129
|
-
debug("Created", identifier.did);
|
|
130
|
-
return identifier;
|
|
131
|
-
}
|
|
132
|
-
async createIdentifierWithCMSM({ kms, options }, context) {
|
|
133
|
-
const cmsmCallbackOpts = this.cmsmCallbackOpts;
|
|
134
|
-
if (!cmsmCallbackOpts) {
|
|
135
|
-
return Promise.reject(Error("did:oyd: no cmsm options defined!"));
|
|
136
|
-
}
|
|
137
|
-
const assertedKms = await this.assertedKms(kms, this.defaultKms);
|
|
138
|
-
const pubKey = options.key ?? await cmsmCallbackOpts.publicKeyCallback(options.kid ?? "default", assertedKms, options.cmsm?.create !== false, options.type);
|
|
139
|
-
const kid = pubKey.kid;
|
|
140
|
-
const keyType = pubKey.type;
|
|
141
|
-
const key = base58btc({
|
|
142
|
-
publicKeyHex: pubKey.publicKeyHex,
|
|
143
|
-
keyType
|
|
144
|
-
});
|
|
145
|
-
console.log(`Bae58 pubkey key: ${key}`);
|
|
146
|
-
let signValue;
|
|
147
|
-
try {
|
|
148
|
-
const body_create = {
|
|
149
|
-
// specify the Identifier options for the registrar
|
|
150
|
-
key,
|
|
151
|
-
options: {
|
|
152
|
-
cmsm: true,
|
|
153
|
-
key_type: keyType
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
console.log(`Create request:
|
|
157
|
-
${JSON.stringify(body_create, null, 2)}
|
|
158
|
-
`);
|
|
159
|
-
const response = await (0, import_cross_fetch.default)(OYDID_REGISTRAR_URL, {
|
|
160
|
-
method: "POST",
|
|
161
|
-
headers: {
|
|
162
|
-
"Content-Type": "application/json"
|
|
163
|
-
},
|
|
164
|
-
body: JSON.stringify(body_create)
|
|
165
|
-
});
|
|
166
|
-
if (!response.ok) {
|
|
167
|
-
debug("Error response from OydDID Registrar: ", body_create, response);
|
|
168
|
-
return Promise.reject(Error("Network response was not ok: " + response.statusText));
|
|
169
|
-
}
|
|
170
|
-
signValue = await response.json();
|
|
171
|
-
console.log(`Create response:
|
|
172
|
-
${JSON.stringify(signValue, null, 2)}
|
|
173
|
-
`);
|
|
174
|
-
} catch (error) {
|
|
175
|
-
console.log("Unexpected error from OydDID Registrar: ", error);
|
|
176
|
-
return Promise.reject(Error("There has been a problem with the fetch operation: " + error.toString()));
|
|
177
|
-
}
|
|
178
|
-
const { sign } = signValue;
|
|
179
|
-
const signature = await cmsmCallbackOpts.signCallback(kid, sign);
|
|
180
|
-
console.log(`Signature: ${signature}`);
|
|
181
|
-
const body_signed = {
|
|
182
|
-
key,
|
|
183
|
-
options: {
|
|
184
|
-
cmsm: true,
|
|
185
|
-
key_type: keyType,
|
|
186
|
-
sig: signature
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
console.log(`Signed request:
|
|
190
|
-
${JSON.stringify(body_signed, null, 2)}
|
|
191
|
-
`);
|
|
192
|
-
let didDoc;
|
|
193
|
-
try {
|
|
194
|
-
const response = await (0, import_cross_fetch.default)(OYDID_REGISTRAR_URL, {
|
|
195
|
-
method: "POST",
|
|
196
|
-
headers: {
|
|
197
|
-
"Content-Type": "application/json"
|
|
198
|
-
},
|
|
199
|
-
body: JSON.stringify(body_signed)
|
|
200
|
-
});
|
|
201
|
-
if (!response.ok) {
|
|
202
|
-
console.log(`Error response from OydDID Registrar: ${JSON.stringify(response.text)}${response.statusText}`, response);
|
|
203
|
-
debug("Error response from OydDID Registrar: ", response);
|
|
204
|
-
return Promise.reject(Error("Network response was not ok: " + response.statusText));
|
|
205
|
-
}
|
|
206
|
-
didDoc = await response.json();
|
|
207
|
-
} catch (error) {
|
|
208
|
-
debug("Unexpected error from OydDID Registrar: ", error);
|
|
209
|
-
return Promise.reject(Error("There has been a problem with the fetch operation: " + error.toString()));
|
|
210
|
-
}
|
|
211
|
-
const identifier = {
|
|
212
|
-
did: didDoc.did,
|
|
213
|
-
controllerKeyId: pubKey.kid,
|
|
214
|
-
keys: [
|
|
215
|
-
pubKey
|
|
216
|
-
],
|
|
217
|
-
services: []
|
|
218
|
-
};
|
|
219
|
-
debug("Created", identifier.did);
|
|
220
|
-
return identifier;
|
|
221
|
-
}
|
|
222
|
-
async updateIdentifier(args, context) {
|
|
223
|
-
throw new Error("OydDIDProvider updateIdentifier not supported yet.");
|
|
224
|
-
}
|
|
225
|
-
async deleteIdentifier(identifier, context) {
|
|
226
|
-
for (const { kid } of identifier.keys) {
|
|
227
|
-
await context.agent.keyManagerDelete({
|
|
228
|
-
kid
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
async addKey({ identifier, key, options }, context) {
|
|
234
|
-
return {
|
|
235
|
-
success: true
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
async addService({ identifier, service, options }, context) {
|
|
239
|
-
return {
|
|
240
|
-
success: true
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
async removeKey(args, context) {
|
|
244
|
-
return {
|
|
245
|
-
success: true
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
async removeService(args, context) {
|
|
249
|
-
return {
|
|
250
|
-
success: true
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
var keyCodecs = {
|
|
255
|
-
RSA: "rsa-pub",
|
|
256
|
-
Ed25519: "ed25519-pub",
|
|
257
|
-
X25519: "x25519-pub",
|
|
258
|
-
Secp256k1: "secp256k1-pub",
|
|
259
|
-
Secp256r1: "p256-pub",
|
|
260
|
-
Bls12381G1: "bls12_381-g1-pub",
|
|
261
|
-
Bls12381G2: "bls12_381-g2-pub"
|
|
262
|
-
};
|
|
263
|
-
var base58btc = /* @__PURE__ */ __name(({ publicKeyHex, keyType = "Secp256r1" }) => {
|
|
264
|
-
const codecName = keyCodecs[keyType];
|
|
265
|
-
return u8a.toString(import_multibase.default.encode("base58btc", import_multicodec.default.addPrefix(codecName, u8a.fromString(publicKeyHex, "hex")))).toString();
|
|
266
|
-
}, "base58btc");
|
|
267
|
-
function defaultOydCmsmPublicKeyCallback(keyManager) {
|
|
268
|
-
return async (kid, kms, create, createKeyType) => {
|
|
269
|
-
try {
|
|
270
|
-
const existing = await keyManager.keyManagerGet({
|
|
271
|
-
kid
|
|
272
|
-
});
|
|
273
|
-
if (existing) {
|
|
274
|
-
return existing;
|
|
275
|
-
}
|
|
276
|
-
} catch (error) {
|
|
277
|
-
}
|
|
278
|
-
if (create) {
|
|
279
|
-
if (!kms) {
|
|
280
|
-
return Promise.reject(Error("No KMS provided, whilst creating a new key!"));
|
|
281
|
-
}
|
|
282
|
-
const alias = kid ?? `oyd-${(/* @__PURE__ */ new Date()).toISOString()}`;
|
|
283
|
-
const agent = keyManager;
|
|
284
|
-
const key = await (0, import_ssi_sdk_ext.importProvidedOrGeneratedKey)({
|
|
285
|
-
kms,
|
|
286
|
-
alias,
|
|
287
|
-
options: {
|
|
288
|
-
key: {
|
|
289
|
-
type: createKeyType ?? "Secp256r1"
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}, {
|
|
293
|
-
//@ts-ignore
|
|
294
|
-
agent
|
|
295
|
-
});
|
|
296
|
-
return key;
|
|
297
|
-
}
|
|
298
|
-
return Promise.reject(Error("No existing key found, and create is false!"));
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
__name(defaultOydCmsmPublicKeyCallback, "defaultOydCmsmPublicKeyCallback");
|
|
302
|
-
function defaultOydCmsmSignCallback(keyManager) {
|
|
303
|
-
return async (kid, data) => {
|
|
304
|
-
return keyManager.keyManagerSign({
|
|
305
|
-
keyRef: kid,
|
|
306
|
-
data,
|
|
307
|
-
encoding: "utf-8"
|
|
308
|
-
});
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
__name(defaultOydCmsmSignCallback, "defaultOydCmsmSignCallback");
|
|
312
|
-
var DefaultOydCmsmCallbacks = class {
|
|
313
|
-
static {
|
|
314
|
-
__name(this, "DefaultOydCmsmCallbacks");
|
|
315
|
-
}
|
|
316
|
-
keyManager;
|
|
317
|
-
constructor(keyManager) {
|
|
318
|
-
this.keyManager = keyManager;
|
|
319
|
-
}
|
|
320
|
-
publicKeyCallback(kid, kms, create, createKeyType) {
|
|
321
|
-
return defaultOydCmsmPublicKeyCallback(this.keyManager)(kid, kms, create, createKeyType);
|
|
322
|
-
}
|
|
323
|
-
signCallback(kid, value) {
|
|
324
|
-
return defaultOydCmsmSignCallback(this.keyManager)(kid, value);
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
// src/resolver.ts
|
|
329
|
-
var import_cross_fetch2 = __toESM(require("cross-fetch"), 1);
|
|
330
|
-
var resolveDidOyd = /* @__PURE__ */ __name(async (didUrl, _parsed, _resolver, options) => {
|
|
331
|
-
try {
|
|
332
|
-
const baseUrl = "https://oydid-resolver.data-container.net";
|
|
333
|
-
const response = await (0, import_cross_fetch2.default)(`${baseUrl}/1.0/identifiers/${didUrl}`);
|
|
334
|
-
if (!response.ok) {
|
|
335
|
-
throw new Error("Network response was not ok: " + response.statusText);
|
|
336
|
-
}
|
|
337
|
-
const didDoc = await response.json();
|
|
338
|
-
return didDoc;
|
|
339
|
-
} catch (err) {
|
|
340
|
-
return {
|
|
341
|
-
didDocumentMetadata: {},
|
|
342
|
-
didResolutionMetadata: {
|
|
343
|
-
error: "invalidDid",
|
|
344
|
-
message: err.toString()
|
|
345
|
-
},
|
|
346
|
-
didDocument: null
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
}, "resolveDidOyd");
|
|
350
|
-
function getDidOydResolver() {
|
|
351
|
-
return {
|
|
352
|
-
oyd: resolveDidOyd
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
__name(getDidOydResolver, "getDidOydResolver");
|
|
356
|
-
//# sourceMappingURL=index.cjs.map
|