@sphereon/ssi-sdk-ext.did-utils 0.28.1-feature.esm.cjs.9 → 0.28.1-feature.jose.vcdm.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/dist/index.cjs +171 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
- package/src/did-functions.ts +16 -17
- package/src/types.ts +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1,18 +1,84 @@
|
|
|
1
|
-
"use strict";
|
|
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;
|
|
2
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
|
+
AgentDIDResolver: () => AgentDIDResolver,
|
|
35
|
+
DID_PREFIX: () => DID_PREFIX,
|
|
36
|
+
IdentifierAliasEnum: () => IdentifierAliasEnum,
|
|
37
|
+
SupportedDidMethodEnum: () => SupportedDidMethodEnum,
|
|
38
|
+
asDidWeb: () => asDidWeb,
|
|
39
|
+
createIdentifier: () => createIdentifier,
|
|
40
|
+
dereferenceDidKeysWithJwkSupport: () => dereferenceDidKeysWithJwkSupport,
|
|
41
|
+
determineKid: () => determineKid,
|
|
42
|
+
didDocumentToJwks: () => didDocumentToJwks,
|
|
43
|
+
extractPublicKeyHex: () => extractPublicKeyHex,
|
|
44
|
+
extractPublicKeyHexWithJwkSupport: () => extractPublicKeyHexWithJwkSupport,
|
|
45
|
+
getAgentDIDMethods: () => getAgentDIDMethods,
|
|
46
|
+
getAgentResolver: () => getAgentResolver,
|
|
47
|
+
getAuthenticationKey: () => getAuthenticationKey,
|
|
48
|
+
getControllerKey: () => getControllerKey,
|
|
49
|
+
getDID: () => getDID,
|
|
50
|
+
getDidSigner: () => getDidSigner,
|
|
51
|
+
getEthereumAddressFromKey: () => getEthereumAddressFromKey,
|
|
52
|
+
getFirstKeyWithRelation: () => getFirstKeyWithRelation,
|
|
53
|
+
getFirstKeyWithRelationFromDIDDoc: () => getFirstKeyWithRelationFromDIDDoc,
|
|
54
|
+
getKey: () => getKey,
|
|
55
|
+
getKeys: () => getKeys,
|
|
56
|
+
getOrCreatePrimaryIdentifier: () => getOrCreatePrimaryIdentifier,
|
|
57
|
+
getPrimaryIdentifier: () => getPrimaryIdentifier,
|
|
58
|
+
getSupportedDIDMethods: () => getSupportedDIDMethods,
|
|
59
|
+
isEvenHexString: () => isEvenHexString,
|
|
60
|
+
jwkTtoPublicKeyHex: () => jwkTtoPublicKeyHex,
|
|
61
|
+
mapIdentifierKeysToDocWithJwkSupport: () => mapIdentifierKeysToDocWithJwkSupport,
|
|
62
|
+
signDidJWT: () => signDidJWT,
|
|
63
|
+
toDID: () => toDID,
|
|
64
|
+
toDIDs: () => toDIDs,
|
|
65
|
+
toDidDocument: () => toDidDocument,
|
|
66
|
+
toDidResolutionResult: () => toDidResolutionResult,
|
|
67
|
+
verificationMethodToJwk: () => verificationMethodToJwk
|
|
68
|
+
});
|
|
69
|
+
module.exports = __toCommonJS(index_exports);
|
|
3
70
|
|
|
4
71
|
// src/did-functions.ts
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var _tostring = require('uint8arrays/to-string');
|
|
72
|
+
var import_transactions = require("@ethersproject/transactions");
|
|
73
|
+
var import_did_uni_client = require("@sphereon/did-uni-client");
|
|
74
|
+
var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
75
|
+
var import_ssi_sdk_ext2 = require("@sphereon/ssi-sdk-ext.x509-utils");
|
|
76
|
+
var import_ssi_sdk = require("@sphereon/ssi-sdk.core");
|
|
77
|
+
var import_ed25519 = require("@stablelib/ed25519");
|
|
78
|
+
var import_utils = require("@veramo/utils");
|
|
79
|
+
var import_did_jwt = require("did-jwt");
|
|
80
|
+
var import_elliptic = __toESM(require("elliptic"), 1);
|
|
81
|
+
var u8a = __toESM(require("uint8arrays"), 1);
|
|
16
82
|
|
|
17
83
|
// src/types.ts
|
|
18
84
|
var SupportedDidMethodEnum = /* @__PURE__ */ function(SupportedDidMethodEnum2) {
|
|
@@ -32,6 +98,7 @@ var IdentifierAliasEnum = /* @__PURE__ */ function(IdentifierAliasEnum2) {
|
|
|
32
98
|
var DID_PREFIX = "did:";
|
|
33
99
|
|
|
34
100
|
// src/did-functions.ts
|
|
101
|
+
var { fromString, toString } = u8a;
|
|
35
102
|
var getAuthenticationKey = /* @__PURE__ */ __name(async ({ identifier, offlineWhenNoDIDRegistered, noVerificationMethodFallback, keyType, controllerKey }, context) => {
|
|
36
103
|
return await getFirstKeyWithRelation({
|
|
37
104
|
identifier,
|
|
@@ -45,19 +112,19 @@ var getAuthenticationKey = /* @__PURE__ */ __name(async ({ identifier, offlineWh
|
|
|
45
112
|
var getFirstKeyWithRelation = /* @__PURE__ */ __name(async ({ identifier, offlineWhenNoDIDRegistered, noVerificationMethodFallback, keyType, controllerKey, vmRelationship }, context) => {
|
|
46
113
|
let key = void 0;
|
|
47
114
|
try {
|
|
48
|
-
key = await
|
|
115
|
+
key = await getFirstKeyWithRelationFromDIDDoc({
|
|
49
116
|
identifier,
|
|
50
117
|
vmRelationship,
|
|
51
118
|
errorOnNotFound: false,
|
|
52
119
|
keyType,
|
|
53
120
|
controllerKey
|
|
54
|
-
}, context)
|
|
121
|
+
}, context) ?? (noVerificationMethodFallback || vmRelationship === "verificationMethod" ? void 0 : await getFirstKeyWithRelationFromDIDDoc({
|
|
55
122
|
identifier,
|
|
56
123
|
vmRelationship: "verificationMethod",
|
|
57
124
|
errorOnNotFound: false,
|
|
58
125
|
keyType,
|
|
59
126
|
controllerKey
|
|
60
|
-
}, context))
|
|
127
|
+
}, context));
|
|
61
128
|
} catch (e) {
|
|
62
129
|
if (e instanceof Error) {
|
|
63
130
|
if (!e.message.includes("404") || !offlineWhenNoDIDRegistered) {
|
|
@@ -69,23 +136,23 @@ var getFirstKeyWithRelation = /* @__PURE__ */ __name(async ({ identifier, offlin
|
|
|
69
136
|
}
|
|
70
137
|
if (!key && offlineWhenNoDIDRegistered) {
|
|
71
138
|
const offlineDID = toDidDocument(identifier);
|
|
72
|
-
key = await
|
|
139
|
+
key = await getFirstKeyWithRelationFromDIDDoc({
|
|
73
140
|
identifier,
|
|
74
141
|
vmRelationship,
|
|
75
142
|
errorOnNotFound: false,
|
|
76
143
|
didDocument: offlineDID,
|
|
77
144
|
keyType,
|
|
78
145
|
controllerKey
|
|
79
|
-
}, context)
|
|
146
|
+
}, context) ?? (noVerificationMethodFallback || vmRelationship === "verificationMethod" ? void 0 : await getFirstKeyWithRelationFromDIDDoc({
|
|
80
147
|
identifier,
|
|
81
148
|
vmRelationship: "verificationMethod",
|
|
82
149
|
errorOnNotFound: false,
|
|
83
150
|
didDocument: offlineDID,
|
|
84
151
|
keyType,
|
|
85
152
|
controllerKey
|
|
86
|
-
}, context))
|
|
153
|
+
}, context));
|
|
87
154
|
if (!key) {
|
|
88
|
-
key = identifier.keys.map((key2) => key2).filter((key2) => keyType === void 0 || key2.type === keyType || controllerKey && key2.kid === identifier.controllerKeyId).find((key2) =>
|
|
155
|
+
key = identifier.keys.map((key2) => key2).filter((key2) => keyType === void 0 || key2.type === keyType || controllerKey && key2.kid === identifier.controllerKeyId).find((key2) => key2.meta.verificationMethod?.type.includes("authentication") || key2.meta.purposes?.includes("authentication"));
|
|
89
156
|
}
|
|
90
157
|
}
|
|
91
158
|
if (!key) {
|
|
@@ -95,8 +162,8 @@ var getFirstKeyWithRelation = /* @__PURE__ */ __name(async ({ identifier, offlin
|
|
|
95
162
|
}, "getFirstKeyWithRelation");
|
|
96
163
|
var getOrCreatePrimaryIdentifier = /* @__PURE__ */ __name(async (context, opts) => {
|
|
97
164
|
const primaryIdentifier = await getPrimaryIdentifier(context, {
|
|
98
|
-
...
|
|
99
|
-
...
|
|
165
|
+
...opts?.createOpts?.options,
|
|
166
|
+
...opts?.method && {
|
|
100
167
|
method: opts.method
|
|
101
168
|
}
|
|
102
169
|
});
|
|
@@ -106,8 +173,8 @@ var getOrCreatePrimaryIdentifier = /* @__PURE__ */ __name(async (context, opts)
|
|
|
106
173
|
result: primaryIdentifier
|
|
107
174
|
};
|
|
108
175
|
}
|
|
109
|
-
if (
|
|
110
|
-
const createOpts =
|
|
176
|
+
if (opts?.method === SupportedDidMethodEnum.DID_KEY) {
|
|
177
|
+
const createOpts = opts?.createOpts ?? {};
|
|
111
178
|
createOpts.options = {
|
|
112
179
|
codecName: "EBSI",
|
|
113
180
|
type: "Secp256r1",
|
|
@@ -122,19 +189,19 @@ var getOrCreatePrimaryIdentifier = /* @__PURE__ */ __name(async (context, opts)
|
|
|
122
189
|
};
|
|
123
190
|
}, "getOrCreatePrimaryIdentifier");
|
|
124
191
|
var getPrimaryIdentifier = /* @__PURE__ */ __name(async (context, opts) => {
|
|
125
|
-
const identifiers = (await context.agent.didManagerFind(
|
|
126
|
-
provider: `${DID_PREFIX}${
|
|
127
|
-
} : {})).filter((identifier) =>
|
|
192
|
+
const identifiers = (await context.agent.didManagerFind(opts?.method ? {
|
|
193
|
+
provider: `${DID_PREFIX}${opts?.method}`
|
|
194
|
+
} : {})).filter((identifier) => opts?.type === void 0 || identifier.keys.some((key) => key.type === opts?.type));
|
|
128
195
|
return identifiers && identifiers.length > 0 ? identifiers[0] : void 0;
|
|
129
196
|
}, "getPrimaryIdentifier");
|
|
130
197
|
var createIdentifier = /* @__PURE__ */ __name(async (context, opts) => {
|
|
131
198
|
return await context.agent.didManagerCreate({
|
|
132
|
-
kms: await
|
|
133
|
-
...
|
|
134
|
-
provider: `${DID_PREFIX}${
|
|
199
|
+
kms: await (0, import_ssi_sdk_ext.getKms)(context, opts?.createOpts?.kms),
|
|
200
|
+
...opts?.method && {
|
|
201
|
+
provider: `${DID_PREFIX}${opts?.method}`
|
|
135
202
|
},
|
|
136
|
-
alias:
|
|
137
|
-
options:
|
|
203
|
+
alias: opts?.createOpts?.alias ?? `${IdentifierAliasEnum.PRIMARY}-${opts?.method}-${opts?.createOpts?.options?.type}-${(/* @__PURE__ */ new Date()).getTime()}`,
|
|
204
|
+
options: opts?.createOpts?.options
|
|
138
205
|
});
|
|
139
206
|
}, "createIdentifier");
|
|
140
207
|
var getFirstKeyWithRelationFromDIDDoc = /* @__PURE__ */ __name(async ({ identifier, vmRelationship = "verificationMethod", keyType, errorOnNotFound = false, didDocument, controllerKey }, context) => {
|
|
@@ -158,7 +225,7 @@ var getEthereumAddressFromKey = /* @__PURE__ */ __name(({ key }) => {
|
|
|
158
225
|
if (key.type !== "Secp256k1") {
|
|
159
226
|
throw Error(`Can only get ethereum address from a Secp256k1 key. Type is ${key.type} for keyRef: ${key.kid}`);
|
|
160
227
|
}
|
|
161
|
-
const ethereumAddress =
|
|
228
|
+
const ethereumAddress = key.meta?.ethereumAddress ?? key.meta?.account?.toLowerCase() ?? (0, import_transactions.computeAddress)(`0x${key.publicKeyHex}`).toLowerCase();
|
|
162
229
|
if (!ethereumAddress) {
|
|
163
230
|
throw Error(`Could not get or generate ethereum address from key with keyRef ${key.kid}`);
|
|
164
231
|
}
|
|
@@ -172,7 +239,7 @@ var getControllerKey = /* @__PURE__ */ __name(({ identifier }) => {
|
|
|
172
239
|
return key;
|
|
173
240
|
}, "getControllerKey");
|
|
174
241
|
var getKeys = /* @__PURE__ */ __name(({ jwkThumbprint, kms, identifier, kmsKeyRef, keyType, controllerKey }) => {
|
|
175
|
-
return identifier.keys.filter((key) => !keyType || key.type === keyType).filter((key) => !kms || key.kms === kms).filter((key) => !kmsKeyRef || key.kid === kmsKeyRef).filter((key) => !jwkThumbprint ||
|
|
242
|
+
return identifier.keys.filter((key) => !keyType || key.type === keyType).filter((key) => !kms || key.kms === kms).filter((key) => !kmsKeyRef || key.kid === kmsKeyRef).filter((key) => !jwkThumbprint || key.meta?.jwkThumbprint === jwkThumbprint).filter((key) => !controllerKey || identifier.controllerKeyId === key.kid);
|
|
176
243
|
}, "getKeys");
|
|
177
244
|
async function dereferenceDidKeysWithJwkSupport(didDocument, section = "keyAgreement", context) {
|
|
178
245
|
const convert = section === "keyAgreement";
|
|
@@ -193,7 +260,7 @@ async function dereferenceDidKeysWithJwkSupport(didDocument, section = "keyAgree
|
|
|
193
260
|
} else {
|
|
194
261
|
return key;
|
|
195
262
|
}
|
|
196
|
-
}))).filter(
|
|
263
|
+
}))).filter(import_utils.isDefined).map((key) => {
|
|
197
264
|
const hexKey = extractPublicKeyHexWithJwkSupport(key, convert);
|
|
198
265
|
const { publicKeyHex, publicKeyBase58, publicKeyBase64, publicKeyJwk, ...keyProps } = key;
|
|
199
266
|
const newKey = {
|
|
@@ -209,31 +276,31 @@ async function dereferenceDidKeysWithJwkSupport(didDocument, section = "keyAgree
|
|
|
209
276
|
__name(dereferenceDidKeysWithJwkSupport, "dereferenceDidKeysWithJwkSupport");
|
|
210
277
|
function jwkTtoPublicKeyHex(jwk) {
|
|
211
278
|
const vm = {
|
|
212
|
-
publicKeyJwk:
|
|
279
|
+
publicKeyJwk: (0, import_ssi_sdk_ext.sanitizedJwk)(jwk)
|
|
213
280
|
};
|
|
214
281
|
return extractPublicKeyHexWithJwkSupport(vm);
|
|
215
282
|
}
|
|
216
283
|
__name(jwkTtoPublicKeyHex, "jwkTtoPublicKeyHex");
|
|
217
284
|
function extractPublicKeyHexWithJwkSupport(pk, convert = false) {
|
|
218
285
|
if (pk.publicKeyJwk) {
|
|
219
|
-
const jwk =
|
|
286
|
+
const jwk = (0, import_ssi_sdk_ext.sanitizedJwk)(pk.publicKeyJwk);
|
|
220
287
|
if (jwk.kty === "EC") {
|
|
221
288
|
const curve = jwk.crv ? toEcLibCurve(jwk.crv) : "p256";
|
|
222
|
-
const xHex =
|
|
223
|
-
const yHex =
|
|
289
|
+
const xHex = (0, import_ssi_sdk_ext2.base64ToHex)(jwk.x, "base64url");
|
|
290
|
+
const yHex = (0, import_ssi_sdk_ext2.base64ToHex)(jwk.y, "base64url");
|
|
224
291
|
const prefix = "04";
|
|
225
292
|
const hex = `${prefix}${xHex}${yHex}`;
|
|
226
293
|
try {
|
|
227
|
-
const ec = new
|
|
294
|
+
const ec = new import_elliptic.default.ec(curve);
|
|
228
295
|
const publicKeyHex = ec.keyFromPublic(hex, "hex").getPublic(true, "hex");
|
|
229
296
|
return publicKeyHex;
|
|
230
297
|
} catch (error) {
|
|
231
298
|
console.error(`Error converting EC with elliptic lib curve ${curve} from JWK to hex. x: ${jwk.x}, y: ${jwk.y}, error: ${error}`, error);
|
|
232
299
|
}
|
|
233
300
|
} else if (jwk.crv === "Ed25519") {
|
|
234
|
-
return
|
|
301
|
+
return toString(fromString(jwk.x, "base64url"), "base16");
|
|
235
302
|
} else if (jwk.kty === "RSA") {
|
|
236
|
-
return
|
|
303
|
+
return (0, import_ssi_sdk_ext2.hexKeyFromPEMBasedJwk)(jwk, "public");
|
|
237
304
|
}
|
|
238
305
|
}
|
|
239
306
|
return extractPublicKeyHex(pk, convert);
|
|
@@ -255,23 +322,23 @@ function isEvenHexString(hex) {
|
|
|
255
322
|
__name(isEvenHexString, "isEvenHexString");
|
|
256
323
|
function extractPublicKeyHex(pk, convert = false) {
|
|
257
324
|
let keyBytes = extractPublicKeyBytes(pk);
|
|
258
|
-
const jwk = pk.publicKeyJwk ?
|
|
325
|
+
const jwk = pk.publicKeyJwk ? (0, import_ssi_sdk_ext.sanitizedJwk)(pk.publicKeyJwk) : void 0;
|
|
259
326
|
if (convert) {
|
|
260
327
|
if ([
|
|
261
328
|
"Ed25519",
|
|
262
329
|
"Ed25519VerificationKey2018",
|
|
263
330
|
"Ed25519VerificationKey2020"
|
|
264
|
-
].includes(pk.type) || pk.type === "JsonWebKey2020" &&
|
|
265
|
-
keyBytes =
|
|
331
|
+
].includes(pk.type) || pk.type === "JsonWebKey2020" && jwk?.crv === "Ed25519") {
|
|
332
|
+
keyBytes = (0, import_ed25519.convertPublicKeyToX25519)(keyBytes);
|
|
266
333
|
} else if (![
|
|
267
334
|
"X25519",
|
|
268
335
|
"X25519KeyAgreementKey2019",
|
|
269
336
|
"X25519KeyAgreementKey2020"
|
|
270
|
-
].includes(pk.type) && !(pk.type === "JsonWebKey2020" &&
|
|
337
|
+
].includes(pk.type) && !(pk.type === "JsonWebKey2020" && jwk?.crv === "X25519")) {
|
|
271
338
|
return "";
|
|
272
339
|
}
|
|
273
340
|
}
|
|
274
|
-
return
|
|
341
|
+
return (0, import_ssi_sdk.bytesToHex)(keyBytes);
|
|
275
342
|
}
|
|
276
343
|
__name(extractPublicKeyHex, "extractPublicKeyHex");
|
|
277
344
|
function toEcLibCurve(input) {
|
|
@@ -280,17 +347,17 @@ function toEcLibCurve(input) {
|
|
|
280
347
|
__name(toEcLibCurve, "toEcLibCurve");
|
|
281
348
|
function extractPublicKeyBytes(pk) {
|
|
282
349
|
if (pk.publicKeyBase58) {
|
|
283
|
-
return
|
|
350
|
+
return (0, import_ssi_sdk.base58ToBytes)(pk.publicKeyBase58);
|
|
284
351
|
} else if (pk.publicKeyMultibase) {
|
|
285
|
-
return
|
|
352
|
+
return (0, import_ssi_sdk.multibaseKeyToBytes)(pk.publicKeyMultibase);
|
|
286
353
|
} else if (pk.publicKeyBase64) {
|
|
287
|
-
return
|
|
354
|
+
return (0, import_ssi_sdk.base64ToBytes)(pk.publicKeyBase64);
|
|
288
355
|
} else if (pk.publicKeyHex) {
|
|
289
|
-
return
|
|
290
|
-
} else if (
|
|
291
|
-
return
|
|
356
|
+
return (0, import_ssi_sdk.hexToBytes)(pk.publicKeyHex);
|
|
357
|
+
} else if (pk.publicKeyJwk?.crv && pk.publicKeyJwk.x && pk.publicKeyJwk.y) {
|
|
358
|
+
return (0, import_ssi_sdk.hexToBytes)(extractPublicKeyHexWithJwkSupport(pk));
|
|
292
359
|
} else if (pk.publicKeyJwk && (pk.publicKeyJwk.crv === "Ed25519" || pk.publicKeyJwk.crv === "X25519") && pk.publicKeyJwk.x) {
|
|
293
|
-
return
|
|
360
|
+
return (0, import_ssi_sdk.base64ToBytes)(pk.publicKeyJwk.x);
|
|
294
361
|
}
|
|
295
362
|
return new Uint8Array();
|
|
296
363
|
}
|
|
@@ -298,8 +365,8 @@ __name(extractPublicKeyBytes, "extractPublicKeyBytes");
|
|
|
298
365
|
function verificationMethodToJwk(vm) {
|
|
299
366
|
let jwk = vm.publicKeyJwk;
|
|
300
367
|
if (!jwk) {
|
|
301
|
-
let publicKeyHex =
|
|
302
|
-
jwk =
|
|
368
|
+
let publicKeyHex = vm.publicKeyHex ?? toString(extractPublicKeyBytes(vm), "hex");
|
|
369
|
+
jwk = (0, import_ssi_sdk_ext.toJwk)(publicKeyHex, (0, import_ssi_sdk_ext.keyTypeFromCryptographicSuite)({
|
|
303
370
|
crv: vm.type
|
|
304
371
|
}));
|
|
305
372
|
}
|
|
@@ -307,11 +374,11 @@ function verificationMethodToJwk(vm) {
|
|
|
307
374
|
throw Error(`Could not convert verification method to jwk`);
|
|
308
375
|
}
|
|
309
376
|
jwk.kid = vm.id;
|
|
310
|
-
return
|
|
377
|
+
return (0, import_ssi_sdk_ext.sanitizedJwk)(jwk);
|
|
311
378
|
}
|
|
312
379
|
__name(verificationMethodToJwk, "verificationMethodToJwk");
|
|
313
380
|
function didDocumentSectionToJwks(didDocumentSection, searchForVerificationMethods, verificationMethods) {
|
|
314
|
-
const jwks = new Set((
|
|
381
|
+
const jwks = new Set((searchForVerificationMethods ?? []).map((vmOrId) => typeof vmOrId === "object" ? vmOrId : verificationMethods?.find((vm) => vm.id === vmOrId)).filter(import_utils.isDefined).map((vm) => verificationMethodToJwk(vm)));
|
|
315
382
|
return {
|
|
316
383
|
didDocumentSection,
|
|
317
384
|
jwks: Array.from(jwks)
|
|
@@ -333,15 +400,15 @@ function didDocumentToJwks(didDocument) {
|
|
|
333
400
|
}
|
|
334
401
|
__name(didDocumentToJwks, "didDocumentToJwks");
|
|
335
402
|
async function mapIdentifierKeysToDocWithJwkSupport({ identifier, vmRelationship = "verificationMethod", didDocument }, context) {
|
|
336
|
-
const didDoc =
|
|
403
|
+
const didDoc = didDocument ?? await getAgentResolver(context).resolve(identifier.did).then((result) => result.didDocument);
|
|
337
404
|
if (!didDoc) {
|
|
338
405
|
throw Error(`Could not resolve DID ${identifier.did}`);
|
|
339
406
|
}
|
|
340
|
-
const keys = didDoc ? [] : await
|
|
407
|
+
const keys = didDoc ? [] : await (0, import_utils.mapIdentifierKeysToDoc)(identifier, vmRelationship, context);
|
|
341
408
|
const documentKeys = await dereferenceDidKeysWithJwkSupport(didDoc, vmRelationship, context);
|
|
342
|
-
const localKeys = vmRelationship === "keyAgreement" ?
|
|
409
|
+
const localKeys = vmRelationship === "keyAgreement" ? (0, import_utils.convertIdentifierEncryptionKeys)(identifier) : (0, import_utils.compressIdentifierSecp256k1Keys)(identifier);
|
|
343
410
|
const extendedKeys = documentKeys.map((verificationMethod) => {
|
|
344
|
-
const localKey = localKeys.find((localKey2) => localKey2.publicKeyHex === verificationMethod.publicKeyHex ||
|
|
411
|
+
const localKey = localKeys.find((localKey2) => localKey2.publicKeyHex === verificationMethod.publicKeyHex || verificationMethod.publicKeyHex?.startsWith(localKey2.publicKeyHex) || compareBlockchainAccountId(localKey2, verificationMethod));
|
|
345
412
|
if (localKey) {
|
|
346
413
|
const { meta, ...localProps } = localKey;
|
|
347
414
|
return {
|
|
@@ -354,7 +421,7 @@ async function mapIdentifierKeysToDocWithJwkSupport({ identifier, vmRelationship
|
|
|
354
421
|
} else {
|
|
355
422
|
return null;
|
|
356
423
|
}
|
|
357
|
-
}).filter(
|
|
424
|
+
}).filter(import_utils.isDefined);
|
|
358
425
|
return keys.concat(extendedKeys);
|
|
359
426
|
}
|
|
360
427
|
__name(mapIdentifierKeysToDocWithJwkSupport, "mapIdentifierKeysToDocWithJwkSupport");
|
|
@@ -362,11 +429,11 @@ function compareBlockchainAccountId(localKey, verificationMethod) {
|
|
|
362
429
|
if (verificationMethod.type !== "EcdsaSecp256k1RecoveryMethod2020" && verificationMethod.type !== "EcdsaSecp256k1VerificationKey2019" || localKey.type !== "Secp256k1") {
|
|
363
430
|
return false;
|
|
364
431
|
}
|
|
365
|
-
let vmEthAddr =
|
|
366
|
-
if (
|
|
367
|
-
return vmEthAddr ===
|
|
432
|
+
let vmEthAddr = (0, import_utils.getEthereumAddress)(verificationMethod);
|
|
433
|
+
if (localKey.meta?.account) {
|
|
434
|
+
return vmEthAddr === localKey.meta?.account.toLowerCase();
|
|
368
435
|
}
|
|
369
|
-
const computedAddr =
|
|
436
|
+
const computedAddr = (0, import_transactions.computeAddress)("0x" + localKey.publicKeyHex).toLowerCase();
|
|
370
437
|
return computedAddr === vmEthAddr;
|
|
371
438
|
}
|
|
372
439
|
__name(compareBlockchainAccountId, "compareBlockchainAccountId");
|
|
@@ -404,9 +471,9 @@ async function getKey({ identifier, vmRelationship = "authentication", kmsKeyRef
|
|
|
404
471
|
if (!identifier) {
|
|
405
472
|
return Promise.reject(new Error(`No identifier provided to getKey method!`));
|
|
406
473
|
}
|
|
407
|
-
const kmsKeyRefParts =
|
|
408
|
-
const kid = kmsKeyRefParts ?
|
|
409
|
-
let identifierKey = kmsKeyRef ? identifier.keys.find((key) => key.kid === kid ||
|
|
474
|
+
const kmsKeyRefParts = kmsKeyRef?.split(`#`);
|
|
475
|
+
const kid = kmsKeyRefParts ? kmsKeyRefParts?.length === 2 ? kmsKeyRefParts[1] : kmsKeyRefParts[0] : void 0;
|
|
476
|
+
let identifierKey = kmsKeyRef ? identifier.keys.find((key) => key.kid === kid || key?.meta?.jwkThumbprint === kid) : void 0;
|
|
410
477
|
if (!identifierKey) {
|
|
411
478
|
const keys = await mapIdentifierKeysToDocWithJwkSupport({
|
|
412
479
|
identifier,
|
|
@@ -416,10 +483,10 @@ async function getKey({ identifier, vmRelationship = "authentication", kmsKeyRef
|
|
|
416
483
|
throw new Error(`No keys found for verificationMethodSection: ${vmRelationship} and did ${identifier.did}`);
|
|
417
484
|
}
|
|
418
485
|
if (kmsKeyRef) {
|
|
419
|
-
identifierKey = keys.find((key) =>
|
|
486
|
+
identifierKey = keys.find((key) => key.meta.verificationMethod?.id === kmsKeyRef || kid && key.meta.verificationMethod?.id?.includes(kid));
|
|
420
487
|
}
|
|
421
488
|
if (!identifierKey) {
|
|
422
|
-
identifierKey = keys.find((key) =>
|
|
489
|
+
identifierKey = keys.find((key) => key.meta.verificationMethod?.type === vmRelationship || key.meta.purposes?.includes(vmRelationship));
|
|
423
490
|
}
|
|
424
491
|
if (!identifierKey) {
|
|
425
492
|
identifierKey = keys[0];
|
|
@@ -441,8 +508,8 @@ async function legacyGetIdentifier({ identifier }, context) {
|
|
|
441
508
|
}
|
|
442
509
|
__name(legacyGetIdentifier, "legacyGetIdentifier");
|
|
443
510
|
async function determineKid({ key, idOpts }, context) {
|
|
444
|
-
if (
|
|
445
|
-
return
|
|
511
|
+
if (key.meta?.verificationMethod?.id) {
|
|
512
|
+
return key.meta?.verificationMethod?.id;
|
|
446
513
|
}
|
|
447
514
|
const identifier = await legacyGetIdentifier(idOpts, context);
|
|
448
515
|
const mappedKeys = await mapIdentifierKeysToDocWithJwkSupport({
|
|
@@ -451,13 +518,13 @@ async function determineKid({ key, idOpts }, context) {
|
|
|
451
518
|
}, context);
|
|
452
519
|
const vmKey = mappedKeys.find((extendedKey) => extendedKey.kid === key.kid);
|
|
453
520
|
if (vmKey) {
|
|
454
|
-
return
|
|
521
|
+
return vmKey.meta?.verificationMethod?.id ?? vmKey.meta?.jwkThumbprint ?? idOpts.kmsKeyRef ?? vmKey.kid;
|
|
455
522
|
}
|
|
456
|
-
return
|
|
523
|
+
return key.meta?.jwkThumbprint ?? idOpts.kmsKeyRef ?? key.kid;
|
|
457
524
|
}
|
|
458
525
|
__name(determineKid, "determineKid");
|
|
459
526
|
async function getSupportedDIDMethods(didOpts, context) {
|
|
460
|
-
return
|
|
527
|
+
return didOpts.supportedDIDMethods ?? await getAgentDIDMethods(context);
|
|
461
528
|
}
|
|
462
529
|
__name(getSupportedDIDMethods, "getSupportedDIDMethods");
|
|
463
530
|
function getAgentResolver(context, opts) {
|
|
@@ -468,15 +535,15 @@ var AgentDIDResolver = class {
|
|
|
468
535
|
static {
|
|
469
536
|
__name(this, "AgentDIDResolver");
|
|
470
537
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
538
|
+
context;
|
|
539
|
+
resolverResolution;
|
|
540
|
+
uniresolverResolution;
|
|
541
|
+
localResolution;
|
|
475
542
|
constructor(context, opts) {
|
|
476
543
|
this.context = context;
|
|
477
|
-
this.resolverResolution =
|
|
478
|
-
this.uniresolverResolution =
|
|
479
|
-
this.localResolution =
|
|
544
|
+
this.resolverResolution = opts?.resolverResolution !== false;
|
|
545
|
+
this.uniresolverResolution = opts?.uniresolverResolution !== false;
|
|
546
|
+
this.localResolution = opts?.localResolution !== false;
|
|
480
547
|
}
|
|
481
548
|
async resolve(didUrl, options) {
|
|
482
549
|
let resolutionResult;
|
|
@@ -534,7 +601,7 @@ var AgentDIDResolver = class {
|
|
|
534
601
|
}
|
|
535
602
|
if (!resolutionResult && this.uniresolverResolution) {
|
|
536
603
|
console.log(`Using universal resolver resolution for did ${didUrl} `);
|
|
537
|
-
resolutionResult = await new
|
|
604
|
+
resolutionResult = await new import_did_uni_client.UniResolver().resolve(didUrl, options);
|
|
538
605
|
if (!origResolutionResult) {
|
|
539
606
|
origResolutionResult = resolutionResult;
|
|
540
607
|
}
|
|
@@ -548,13 +615,13 @@ var AgentDIDResolver = class {
|
|
|
548
615
|
if (!resolutionResult && !origResolutionResult) {
|
|
549
616
|
throw `Could not resolve ${didUrl}. Resolutions tried: online: ${this.resolverResolution}, local: ${this.localResolution}, uni resolver: ${this.uniresolverResolution}`;
|
|
550
617
|
}
|
|
551
|
-
return
|
|
618
|
+
return resolutionResult ?? origResolutionResult;
|
|
552
619
|
}
|
|
553
620
|
};
|
|
554
621
|
function toDidDocument(identifier, opts) {
|
|
555
622
|
let didDocument = void 0;
|
|
556
623
|
if (identifier) {
|
|
557
|
-
const did =
|
|
624
|
+
const did = identifier.did ?? opts?.did;
|
|
558
625
|
didDocument = {
|
|
559
626
|
"@context": "https://www.w3.org/ns/did/v1",
|
|
560
627
|
id: did,
|
|
@@ -562,48 +629,48 @@ function toDidDocument(identifier, opts) {
|
|
|
562
629
|
const vm = {
|
|
563
630
|
controller: did,
|
|
564
631
|
id: key.kid.startsWith(did) && key.kid.includes("#") ? key.kid : `${did}#${key.kid}`,
|
|
565
|
-
publicKeyJwk:
|
|
566
|
-
use:
|
|
632
|
+
publicKeyJwk: (0, import_ssi_sdk_ext.toJwk)(key.publicKeyHex, key.type, {
|
|
633
|
+
use: import_ssi_sdk_ext.ENC_KEY_ALGS.includes(key.type) ? import_ssi_sdk_ext.JwkKeyUse.Encryption : import_ssi_sdk_ext.JwkKeyUse.Signature,
|
|
567
634
|
key
|
|
568
635
|
}),
|
|
569
636
|
type: "JsonWebKey2020"
|
|
570
637
|
};
|
|
571
638
|
return vm;
|
|
572
639
|
}),
|
|
573
|
-
...(
|
|
574
|
-
assertionMethod: identifier.keys.filter((key) =>
|
|
640
|
+
...(opts?.use === void 0 || opts?.use?.includes(import_ssi_sdk_ext.JwkKeyUse.Signature)) && identifier.keys && {
|
|
641
|
+
assertionMethod: identifier.keys.filter((key) => key?.meta?.purpose === void 0 || key?.meta?.purpose === "assertionMethod" || key?.meta?.purposes?.includes("assertionMethod")).map((key) => {
|
|
575
642
|
if (key.kid.startsWith(did) && key.kid.includes("#")) {
|
|
576
643
|
return key.kid;
|
|
577
644
|
}
|
|
578
645
|
return `${did}#${key.kid}`;
|
|
579
646
|
})
|
|
580
647
|
},
|
|
581
|
-
...(
|
|
582
|
-
authentication: identifier.keys.filter((key) =>
|
|
648
|
+
...(opts?.use === void 0 || opts?.use?.includes(import_ssi_sdk_ext.JwkKeyUse.Signature)) && identifier.keys && {
|
|
649
|
+
authentication: identifier.keys.filter((key) => key?.meta?.purpose === void 0 || key?.meta?.purpose === "authentication" || key?.meta?.purposes?.includes("authentication")).map((key) => {
|
|
583
650
|
if (key.kid.startsWith(did) && key.kid.includes("#")) {
|
|
584
651
|
return key.kid;
|
|
585
652
|
}
|
|
586
653
|
return `${did}#${key.kid}`;
|
|
587
654
|
})
|
|
588
655
|
},
|
|
589
|
-
...(
|
|
590
|
-
keyAgreement: identifier.keys.filter((key) => key.type === "X25519" ||
|
|
656
|
+
...(opts?.use === void 0 || opts?.use?.includes(import_ssi_sdk_ext.JwkKeyUse.Encryption)) && identifier.keys && {
|
|
657
|
+
keyAgreement: identifier.keys.filter((key) => key.type === "X25519" || key?.meta?.purpose === "keyAgreement" || key?.meta?.purposes?.includes("keyAgreement")).map((key) => {
|
|
591
658
|
if (key.kid.startsWith(did) && key.kid.includes("#")) {
|
|
592
659
|
return key.kid;
|
|
593
660
|
}
|
|
594
661
|
return `${did}#${key.kid}`;
|
|
595
662
|
})
|
|
596
663
|
},
|
|
597
|
-
...(
|
|
598
|
-
capabilityInvocation: identifier.keys.filter((key) => key.type === "X25519" ||
|
|
664
|
+
...(opts?.use === void 0 || opts?.use?.includes(import_ssi_sdk_ext.JwkKeyUse.Encryption)) && identifier.keys && {
|
|
665
|
+
capabilityInvocation: identifier.keys.filter((key) => key.type === "X25519" || key?.meta?.purpose === "capabilityInvocation" || key?.meta?.purposes?.includes("capabilityInvocation")).map((key) => {
|
|
599
666
|
if (key.kid.startsWith(did) && key.kid.includes("#")) {
|
|
600
667
|
return key.kid;
|
|
601
668
|
}
|
|
602
669
|
return `${did}#${key.kid}`;
|
|
603
670
|
})
|
|
604
671
|
},
|
|
605
|
-
...(
|
|
606
|
-
capabilityDelegation: identifier.keys.filter((key) => key.type === "X25519" ||
|
|
672
|
+
...(opts?.use === void 0 || opts?.use?.includes(import_ssi_sdk_ext.JwkKeyUse.Encryption)) && identifier.keys && {
|
|
673
|
+
capabilityDelegation: identifier.keys.filter((key) => key.type === "X25519" || key?.meta?.purpose === "capabilityDelegation" || key?.meta?.purposes?.includes("capabilityDelegation")).map((key) => {
|
|
607
674
|
if (key.kid.startsWith(did) && key.kid.includes("#")) {
|
|
608
675
|
return key.kid;
|
|
609
676
|
}
|
|
@@ -619,7 +686,7 @@ function toDidDocument(identifier, opts) {
|
|
|
619
686
|
}
|
|
620
687
|
__name(toDidDocument, "toDidDocument");
|
|
621
688
|
function toDidResolutionResult(identifier, opts) {
|
|
622
|
-
const didDocument =
|
|
689
|
+
const didDocument = toDidDocument(identifier, opts) ?? null;
|
|
623
690
|
const resolutionResult = {
|
|
624
691
|
"@context": "https://w3id.org/did-resolution/v1",
|
|
625
692
|
didDocument,
|
|
@@ -627,13 +694,13 @@ function toDidResolutionResult(identifier, opts) {
|
|
|
627
694
|
...!didDocument && {
|
|
628
695
|
error: "notFound"
|
|
629
696
|
},
|
|
630
|
-
...Array.isArray(
|
|
697
|
+
...Array.isArray(opts?.supportedMethods) && identifier && !opts?.supportedMethods.includes(identifier.provider.replace("did:", "")) && {
|
|
631
698
|
error: "unsupportedDidMethod"
|
|
632
699
|
}
|
|
633
700
|
},
|
|
634
701
|
didDocumentMetadata: {
|
|
635
|
-
...
|
|
636
|
-
equivalentId:
|
|
702
|
+
...identifier?.alias && {
|
|
703
|
+
equivalentId: identifier?.alias
|
|
637
704
|
}
|
|
638
705
|
}
|
|
639
706
|
};
|
|
@@ -660,7 +727,7 @@ var signDidJWT = /* @__PURE__ */ __name(async (args) => {
|
|
|
660
727
|
context
|
|
661
728
|
})
|
|
662
729
|
};
|
|
663
|
-
return
|
|
730
|
+
return (0, import_did_jwt.createJWT)(payload, jwtOptions, header);
|
|
664
731
|
}, "signDidJWT");
|
|
665
732
|
var getDidSigner = /* @__PURE__ */ __name(async (args) => {
|
|
666
733
|
const { idOpts, context } = args;
|
|
@@ -670,7 +737,7 @@ var getDidSigner = /* @__PURE__ */ __name(async (args) => {
|
|
|
670
737
|
vmRelationship: idOpts.verificationMethodSection,
|
|
671
738
|
kmsKeyRef: idOpts.kmsKeyRef
|
|
672
739
|
}, context);
|
|
673
|
-
const algorithm = await
|
|
740
|
+
const algorithm = await (0, import_ssi_sdk_ext.signatureAlgorithmFromKey)({
|
|
674
741
|
key
|
|
675
742
|
});
|
|
676
743
|
return async (data) => {
|
|
@@ -682,40 +749,4 @@ var getDidSigner = /* @__PURE__ */ __name(async (args) => {
|
|
|
682
749
|
});
|
|
683
750
|
};
|
|
684
751
|
}, "getDidSigner");
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
exports.AgentDIDResolver = AgentDIDResolver; exports.DID_PREFIX = DID_PREFIX; exports.IdentifierAliasEnum = IdentifierAliasEnum; exports.SupportedDidMethodEnum = SupportedDidMethodEnum; exports.asDidWeb = asDidWeb; exports.createIdentifier = createIdentifier; exports.dereferenceDidKeysWithJwkSupport = dereferenceDidKeysWithJwkSupport; exports.determineKid = determineKid; exports.didDocumentToJwks = didDocumentToJwks; exports.extractPublicKeyHex = extractPublicKeyHex; exports.extractPublicKeyHexWithJwkSupport = extractPublicKeyHexWithJwkSupport; exports.getAgentDIDMethods = getAgentDIDMethods; exports.getAgentResolver = getAgentResolver; exports.getAuthenticationKey = getAuthenticationKey; exports.getControllerKey = getControllerKey; exports.getDID = getDID; exports.getDidSigner = getDidSigner; exports.getEthereumAddressFromKey = getEthereumAddressFromKey; exports.getFirstKeyWithRelation = getFirstKeyWithRelation; exports.getFirstKeyWithRelationFromDIDDoc = getFirstKeyWithRelationFromDIDDoc; exports.getKey = getKey; exports.getKeys = getKeys; exports.getOrCreatePrimaryIdentifier = getOrCreatePrimaryIdentifier; exports.getPrimaryIdentifier = getPrimaryIdentifier; exports.getSupportedDIDMethods = getSupportedDIDMethods; exports.isEvenHexString = isEvenHexString; exports.jwkTtoPublicKeyHex = jwkTtoPublicKeyHex; exports.mapIdentifierKeysToDocWithJwkSupport = mapIdentifierKeysToDocWithJwkSupport; exports.signDidJWT = signDidJWT; exports.toDID = toDID; exports.toDIDs = toDIDs; exports.toDidDocument = toDidDocument; exports.toDidResolutionResult = toDidResolutionResult; exports.verificationMethodToJwk = verificationMethodToJwk;
|
|
721
752
|
//# sourceMappingURL=index.cjs.map
|