@sphereon/ssi-sdk-ext.key-utils 0.14.1-unstable.7 → 0.14.2-next.3
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/digest-methods.d.ts +7 -0
- package/dist/digest-methods.d.ts.map +1 -0
- package/dist/digest-methods.js +95 -0
- package/dist/digest-methods.js.map +1 -0
- package/dist/functions.d.ts +44 -0
- package/dist/functions.d.ts.map +1 -0
- package/dist/functions.js +236 -0
- package/dist/functions.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/jwk-jcs.d.ts +22 -0
- package/dist/jwk-jcs.d.ts.map +1 -0
- package/dist/jwk-jcs.js +178 -0
- package/dist/jwk-jcs.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/key-util-types.d.ts +49 -0
- package/dist/types/key-util-types.d.ts.map +1 -0
- package/dist/types/key-util-types.js +37 -0
- package/dist/types/key-util-types.js.map +1 -0
- package/dist/x509/index.d.ts +4 -0
- package/dist/x509/index.d.ts.map +1 -0
- package/dist/x509/index.js +20 -0
- package/dist/x509/index.js.map +1 -0
- package/dist/x509/rsa-key.d.ts +11 -0
- package/dist/x509/rsa-key.d.ts.map +1 -0
- package/dist/x509/rsa-key.js +83 -0
- package/dist/x509/rsa-key.js.map +1 -0
- package/dist/x509/rsa-signer.d.ts +25 -0
- package/dist/x509/rsa-signer.d.ts.map +1 -0
- package/dist/x509/rsa-signer.js +101 -0
- package/dist/x509/rsa-signer.js.map +1 -0
- package/dist/x509/x509-utils.d.ts +24 -0
- package/dist/x509/x509-utils.d.ts.map +1 -0
- package/dist/x509/x509-utils.js +175 -0
- package/dist/x509/x509-utils.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type HashAlgorithm = 'SHA-256' | 'SHA-512';
|
|
2
|
+
export type TDigestMethod = (input: string) => string;
|
|
3
|
+
export declare const digestMethodParams: (hashAlgorithm: HashAlgorithm) => {
|
|
4
|
+
hashAlgorithm: HashAlgorithm;
|
|
5
|
+
digestMethod: TDigestMethod;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=digest-methods.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digest-methods.d.ts","sourceRoot":"","sources":["../src/digest-methods.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,SAAS,CAAA;AACjD,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;AAErD,eAAO,MAAM,kBAAkB,kBAAmB,aAAa;mBAAoB,aAAa;kBAAgB,aAAa;CAM5H,CAAA"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.digestMethodParams = void 0;
|
|
27
|
+
const sha256_1 = require("@stablelib/sha256");
|
|
28
|
+
const sha512_1 = require("@stablelib/sha512");
|
|
29
|
+
const u8a = __importStar(require("uint8arrays"));
|
|
30
|
+
const digestMethodParams = (hashAlgorithm) => {
|
|
31
|
+
if (hashAlgorithm === 'SHA-256') {
|
|
32
|
+
return { hashAlgorithm: 'SHA-256', digestMethod: sha256DigestMethod };
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return { hashAlgorithm: 'SHA-512', digestMethod: sha512DigestMethod };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.digestMethodParams = digestMethodParams;
|
|
39
|
+
const sha256DigestMethod = (input) => {
|
|
40
|
+
return u8a.toString((0, sha256_1.hash)(u8a.fromString(input, 'utf-8')), 'base16');
|
|
41
|
+
};
|
|
42
|
+
const sha512DigestMethod = (input) => {
|
|
43
|
+
return u8a.toString((0, sha512_1.hash)(u8a.fromString(input, 'utf-8')), 'base16');
|
|
44
|
+
};
|
|
45
|
+
/*
|
|
46
|
+
// PKCS#1 (PSS) mask generation function
|
|
47
|
+
function pss_mgf1_str(seed, len, hash) {
|
|
48
|
+
var mask = '', i = 0;
|
|
49
|
+
|
|
50
|
+
while (mask.length < len) {
|
|
51
|
+
mask += hextorstr(hash(rstrtohex(seed + String.fromCharCode.apply(String, [
|
|
52
|
+
(i & 0xff000000) >> 24,
|
|
53
|
+
(i & 0x00ff0000) >> 16,
|
|
54
|
+
(i & 0x0000ff00) >> 8,
|
|
55
|
+
i & 0x000000ff]))));
|
|
56
|
+
i += 1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return mask;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
*/
|
|
63
|
+
/*
|
|
64
|
+
|
|
65
|
+
/!**
|
|
66
|
+
* Generate mask of specified length.
|
|
67
|
+
*
|
|
68
|
+
* @param {String} seed The seed for mask generation.
|
|
69
|
+
* @param maskLen Number of bytes to generate.
|
|
70
|
+
* @return {String} The generated mask.
|
|
71
|
+
*!/
|
|
72
|
+
export const mgf1 = (dm: TDigestMethod, seed: string, maskLen: number) => {
|
|
73
|
+
/!* 2. Let T be the empty octet string. *!/
|
|
74
|
+
var t = new forge.util.ByteBuffer();
|
|
75
|
+
|
|
76
|
+
/!* 3. For counter from 0 to ceil(maskLen / hLen), do the following: *!/
|
|
77
|
+
var len = Math.ceil(maskLen / md.digestLength);
|
|
78
|
+
for(var i = 0; i < len; i++) {
|
|
79
|
+
/!* a. Convert counter to an octet string C of length 4 octets *!/
|
|
80
|
+
var c = new forge.util.ByteBuffer();
|
|
81
|
+
c.putInt32(i);
|
|
82
|
+
|
|
83
|
+
/!* b. Concatenate the hash of the seed mgfSeed and C to the octet
|
|
84
|
+
* string T: *!/
|
|
85
|
+
md.start();
|
|
86
|
+
md.update(seed + c.getBytes());
|
|
87
|
+
t.putBuffer(md.digest());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/!* Output the leading maskLen octets of T as the octet string mask. *!/
|
|
91
|
+
t.truncate(t.length() - maskLen);
|
|
92
|
+
return t.getBytes();
|
|
93
|
+
}
|
|
94
|
+
*/
|
|
95
|
+
//# sourceMappingURL=digest-methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digest-methods.js","sourceRoot":"","sources":["../src/digest-methods.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAkD;AAClD,8CAAkD;AAClD,iDAAkC;AAK3B,MAAM,kBAAkB,GAAG,CAAC,aAA4B,EAAiE,EAAE;IAChI,IAAI,aAAa,KAAK,SAAS,EAAE;QAC/B,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,kBAAkB,EAAE,CAAA;KACtE;SAAM;QACL,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,kBAAkB,EAAE,CAAA;KACtE;AACH,CAAC,CAAA;AANY,QAAA,kBAAkB,sBAM9B;AAED,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAU,EAAE;IACnD,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAA,aAAM,EAAC,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;AACvE,CAAC,CAAA;AAED,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAU,EAAE;IACnD,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAA,aAAM,EAAC,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;AACvE,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { IAgentContext, IKey, IKeyManager } from '@veramo/core';
|
|
2
|
+
import { JsonWebKey } from 'did-resolver';
|
|
3
|
+
import { IImportProvidedOrGeneratedKeyArgs, JwkKeyUse, TKeyType } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Generates a random Private Hex Key for the specified key type
|
|
6
|
+
* @param type The key type
|
|
7
|
+
* @return The private key in Hex form
|
|
8
|
+
*/
|
|
9
|
+
export declare const generatePrivateKeyHex: (type: TKeyType) => Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* We optionally generate and then import our own keys.
|
|
12
|
+
*
|
|
13
|
+
* @param args The key arguments
|
|
14
|
+
* @param context The Veramo agent context
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
export declare function importProvidedOrGeneratedKey(args: IImportProvidedOrGeneratedKeyArgs & {
|
|
18
|
+
kms: string;
|
|
19
|
+
}, context: IAgentContext<IKeyManager>): Promise<IKey>;
|
|
20
|
+
/**
|
|
21
|
+
* Converts hex value to base64url
|
|
22
|
+
* @param value hex value
|
|
23
|
+
* @return Base64Url encoded value
|
|
24
|
+
*/
|
|
25
|
+
export declare const hex2base64url: (value: string) => string;
|
|
26
|
+
/**
|
|
27
|
+
* Converts a public key in hex format to a JWK
|
|
28
|
+
* @param publicKeyHex public key in hex
|
|
29
|
+
* @param type The type of the key (Ed25519, Secp256k1/r1)
|
|
30
|
+
* @param opts. Options, like the optional use for the key (sig/enc)
|
|
31
|
+
* @return The JWK
|
|
32
|
+
*/
|
|
33
|
+
export declare const toJwk: (publicKeyHex: string, type: TKeyType, opts?: {
|
|
34
|
+
use?: JwkKeyUse;
|
|
35
|
+
key?: IKey;
|
|
36
|
+
}) => JsonWebKey;
|
|
37
|
+
/**
|
|
38
|
+
* Determines the use param based upon the key/signature type or supplied use value.
|
|
39
|
+
*
|
|
40
|
+
* @param type The key type
|
|
41
|
+
* @param suppliedUse A supplied use. Will be used in case it is present
|
|
42
|
+
*/
|
|
43
|
+
export declare const jwkDetermineUse: (type: TKeyType, suppliedUse?: JwkKeyUse) => JwkKeyUse | undefined;
|
|
44
|
+
//# sourceMappingURL=functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAGzC,OAAO,EAAgB,iCAAiC,EAAE,SAAS,EAAmC,QAAQ,EAAE,MAAM,SAAS,CAAA;AAG/H;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,SAAgB,QAAQ,KAAG,QAAQ,MAAM,CAmB1E,CAAA;AAED;;;;;;GAMG;AACH,wBAAsB,4BAA4B,CAChD,IAAI,EAAE,iCAAiC,GAAG;IACxC,GAAG,EAAE,MAAM,CAAA;CACZ,EACD,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,GAClC,OAAO,CAAC,IAAI,CAAC,CAuCf;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,WAO1C,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,iBAAkB,MAAM,QAAQ,QAAQ,SAAS;IAAE,GAAG,CAAC,EAAE,SAAS,CAAC;IAAC,GAAG,CAAC,EAAE,IAAI,CAAA;CAAE,KAAG,UAoBpG,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,SAAU,QAAQ,gBAAgB,SAAS,KAAG,SAAS,GAAG,SAQrF,CAAA"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.jwkDetermineUse = exports.toJwk = exports.hex2base64url = exports.importProvidedOrGeneratedKey = exports.generatePrivateKeyHex = void 0;
|
|
39
|
+
const random_1 = require("@ethersproject/random");
|
|
40
|
+
const ed25519_1 = require("@stablelib/ed25519");
|
|
41
|
+
const elliptic_1 = __importDefault(require("elliptic"));
|
|
42
|
+
const u8a = __importStar(require("uint8arrays"));
|
|
43
|
+
const types_1 = require("./types");
|
|
44
|
+
const x509_1 = require("./x509");
|
|
45
|
+
/**
|
|
46
|
+
* Generates a random Private Hex Key for the specified key type
|
|
47
|
+
* @param type The key type
|
|
48
|
+
* @return The private key in Hex form
|
|
49
|
+
*/
|
|
50
|
+
const generatePrivateKeyHex = (type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
switch (type) {
|
|
52
|
+
case 'Ed25519': {
|
|
53
|
+
const keyPairEd25519 = (0, ed25519_1.generateKeyPair)();
|
|
54
|
+
return u8a.toString(keyPairEd25519.secretKey, 'base16');
|
|
55
|
+
}
|
|
56
|
+
// The Secp256 types use the same method to generate the key
|
|
57
|
+
case 'Secp256r1':
|
|
58
|
+
case 'Secp256k1': {
|
|
59
|
+
const privateBytes = (0, random_1.randomBytes)(32);
|
|
60
|
+
return u8a.toString(privateBytes, 'base16');
|
|
61
|
+
}
|
|
62
|
+
case 'RSA': {
|
|
63
|
+
const pem = yield (0, x509_1.generateRSAKeyAsPEM)('RSA-PSS', 'SHA-256', 2048);
|
|
64
|
+
return (0, x509_1.privateKeyHexFromPEM)(pem);
|
|
65
|
+
}
|
|
66
|
+
default:
|
|
67
|
+
throw Error(`not_supported: Key type ${type} not yet supported for this did:jwk implementation`);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
exports.generatePrivateKeyHex = generatePrivateKeyHex;
|
|
71
|
+
/**
|
|
72
|
+
* We optionally generate and then import our own keys.
|
|
73
|
+
*
|
|
74
|
+
* @param args The key arguments
|
|
75
|
+
* @param context The Veramo agent context
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
function importProvidedOrGeneratedKey(args, context) {
|
|
79
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
const type = (_g = (_e = (_b = (_a = args.options) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : (_d = (_c = args.options) === null || _c === void 0 ? void 0 : _c.key) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : (_f = args.options) === null || _f === void 0 ? void 0 : _f.keyType) !== null && _g !== void 0 ? _g : 'Secp256r1';
|
|
83
|
+
const key = (_h = args === null || args === void 0 ? void 0 : args.options) === null || _h === void 0 ? void 0 : _h.key;
|
|
84
|
+
// Make sure x509 options are also set on the metadata as that is what the kms will look for
|
|
85
|
+
if (((_j = args.options) === null || _j === void 0 ? void 0 : _j.x509) && key) {
|
|
86
|
+
key.meta = Object.assign(Object.assign({}, key.meta), { x509: Object.assign(Object.assign({}, args.options.x509), (_k = key.meta) === null || _k === void 0 ? void 0 : _k.x509) });
|
|
87
|
+
}
|
|
88
|
+
if (args.options && ((_l = args.options) === null || _l === void 0 ? void 0 : _l.use) === types_1.JwkKeyUse.Encryption && !types_1.ENC_KEY_ALGS.includes(type)) {
|
|
89
|
+
throw new Error(`${type} keys are not valid for encryption`);
|
|
90
|
+
}
|
|
91
|
+
let privateKeyHex;
|
|
92
|
+
if (key) {
|
|
93
|
+
privateKeyHex = (_m = key.privateKeyHex) !== null && _m !== void 0 ? _m : (_p = (_o = key.meta) === null || _o === void 0 ? void 0 : _o.x509) === null || _p === void 0 ? void 0 : _p.privateKeyHex;
|
|
94
|
+
if ((!privateKeyHex || privateKeyHex.trim() === '') && ((_r = (_q = key === null || key === void 0 ? void 0 : key.meta) === null || _q === void 0 ? void 0 : _q.x509) === null || _r === void 0 ? void 0 : _r.privateKeyPEM)) {
|
|
95
|
+
// If we do not have a privateKeyHex but do have a PEM
|
|
96
|
+
privateKeyHex = (0, x509_1.privateKeyHexFromPEM)(key.meta.x509.privateKeyPEM);
|
|
97
|
+
}
|
|
98
|
+
if (!privateKeyHex && !((_t = (_s = key.meta) === null || _s === void 0 ? void 0 : _s.x509) === null || _t === void 0 ? void 0 : _t.privateKeyPEM)) {
|
|
99
|
+
throw new Error(`We need to have a private key in Hex or PEM when importing a key`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
privateKeyHex = yield (0, exports.generatePrivateKeyHex)(type);
|
|
104
|
+
}
|
|
105
|
+
return context.agent.keyManagerImport(Object.assign(Object.assign({}, key), { kms: args.kms, type,
|
|
106
|
+
privateKeyHex }));
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
exports.importProvidedOrGeneratedKey = importProvidedOrGeneratedKey;
|
|
110
|
+
/**
|
|
111
|
+
* Converts hex value to base64url
|
|
112
|
+
* @param value hex value
|
|
113
|
+
* @return Base64Url encoded value
|
|
114
|
+
*/
|
|
115
|
+
const hex2base64url = (value) => {
|
|
116
|
+
//fixme: Buffer to u8a
|
|
117
|
+
const buffer = Buffer.from(value, 'hex');
|
|
118
|
+
const base64 = buffer.toString('base64');
|
|
119
|
+
const base64url = base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
120
|
+
return base64url;
|
|
121
|
+
};
|
|
122
|
+
exports.hex2base64url = hex2base64url;
|
|
123
|
+
/**
|
|
124
|
+
* Converts a public key in hex format to a JWK
|
|
125
|
+
* @param publicKeyHex public key in hex
|
|
126
|
+
* @param type The type of the key (Ed25519, Secp256k1/r1)
|
|
127
|
+
* @param opts. Options, like the optional use for the key (sig/enc)
|
|
128
|
+
* @return The JWK
|
|
129
|
+
*/
|
|
130
|
+
const toJwk = (publicKeyHex, type, opts) => {
|
|
131
|
+
const { key } = opts !== null && opts !== void 0 ? opts : {};
|
|
132
|
+
if (key && key.publicKeyHex !== publicKeyHex) {
|
|
133
|
+
throw Error(`Provided key with id ${key.kid}, has a different public key hex than supplied public key ${publicKeyHex}`);
|
|
134
|
+
}
|
|
135
|
+
switch (type) {
|
|
136
|
+
case 'Ed25519':
|
|
137
|
+
return toEd25519OrX25519Jwk(publicKeyHex, Object.assign(Object.assign({}, opts), { crv: types_1.KeyCurve.Ed25519 }));
|
|
138
|
+
case 'X25519':
|
|
139
|
+
return toEd25519OrX25519Jwk(publicKeyHex, Object.assign(Object.assign({}, opts), { crv: types_1.KeyCurve.X25519 }));
|
|
140
|
+
case 'Secp256k1':
|
|
141
|
+
return toSecp256k1Jwk(publicKeyHex, opts);
|
|
142
|
+
case 'Secp256r1':
|
|
143
|
+
return toSecp256r1Jwk(publicKeyHex, opts);
|
|
144
|
+
case 'RSA':
|
|
145
|
+
return toRSAJwk(publicKeyHex, opts);
|
|
146
|
+
default:
|
|
147
|
+
throw new Error(`not_supported: Key type ${type} not yet supported for this did:jwk implementation`);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
exports.toJwk = toJwk;
|
|
151
|
+
/**
|
|
152
|
+
* Determines the use param based upon the key/signature type or supplied use value.
|
|
153
|
+
*
|
|
154
|
+
* @param type The key type
|
|
155
|
+
* @param suppliedUse A supplied use. Will be used in case it is present
|
|
156
|
+
*/
|
|
157
|
+
const jwkDetermineUse = (type, suppliedUse) => {
|
|
158
|
+
return suppliedUse
|
|
159
|
+
? suppliedUse
|
|
160
|
+
: types_1.SIG_KEY_ALGS.includes(type)
|
|
161
|
+
? types_1.JwkKeyUse.Signature
|
|
162
|
+
: types_1.ENC_KEY_ALGS.includes(type)
|
|
163
|
+
? types_1.JwkKeyUse.Encryption
|
|
164
|
+
: undefined;
|
|
165
|
+
};
|
|
166
|
+
exports.jwkDetermineUse = jwkDetermineUse;
|
|
167
|
+
/**
|
|
168
|
+
* Assert the key has a proper length
|
|
169
|
+
*
|
|
170
|
+
* @param keyHex Input key
|
|
171
|
+
* @param expectedKeyLength Expected key length(s)
|
|
172
|
+
*/
|
|
173
|
+
const assertProperKeyLength = (keyHex, expectedKeyLength) => {
|
|
174
|
+
if (Array.isArray(expectedKeyLength)) {
|
|
175
|
+
if (!expectedKeyLength.includes(keyHex.length)) {
|
|
176
|
+
throw Error(`Invalid key length. Needs to be a hex string with length from ${JSON.stringify(expectedKeyLength)} instead of ${keyHex.length}. Input: ${keyHex}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else if (keyHex.length !== expectedKeyLength) {
|
|
180
|
+
throw Error(`Invalid key length. Needs to be a hex string with length ${expectedKeyLength} instead of ${keyHex.length}. Input: ${keyHex}`);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Generates a JWK from a Secp256k1 public key
|
|
185
|
+
* @param publicKeyHex Secp256k1 public key in hex
|
|
186
|
+
* @param use The use for the key
|
|
187
|
+
* @return The JWK
|
|
188
|
+
*/
|
|
189
|
+
const toSecp256k1Jwk = (publicKeyHex, opts) => {
|
|
190
|
+
const { use } = opts !== null && opts !== void 0 ? opts : {};
|
|
191
|
+
const publicKey = publicKeyHex;
|
|
192
|
+
assertProperKeyLength(publicKeyHex, [64, 66, 130]);
|
|
193
|
+
const secp256r1 = new elliptic_1.default.ec('secp256k1');
|
|
194
|
+
const key = secp256r1.keyFromPublic(publicKey, 'hex');
|
|
195
|
+
const pubPoint = key.getPublic();
|
|
196
|
+
return Object.assign(Object.assign({ alg: 'ES256K' }, (use !== undefined && { use })), { kty: types_1.KeyType.EC, crv: types_1.KeyCurve.Secp256k1, x: (0, exports.hex2base64url)(pubPoint.getX().toString('hex')), y: (0, exports.hex2base64url)(pubPoint.getY().toString('hex')) });
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Generates a JWK from a Secp256r1 public key
|
|
200
|
+
* @param publicKeyHex Secp256r1 public key in hex
|
|
201
|
+
* @param use The use for the key
|
|
202
|
+
* @return The JWK
|
|
203
|
+
*/
|
|
204
|
+
const toSecp256r1Jwk = (publicKeyHex, opts) => {
|
|
205
|
+
const { use } = opts !== null && opts !== void 0 ? opts : {};
|
|
206
|
+
const publicKey = publicKeyHex;
|
|
207
|
+
assertProperKeyLength(publicKey, [64, 66, 130]);
|
|
208
|
+
const secp256r1 = new elliptic_1.default.ec('p256');
|
|
209
|
+
const key = secp256r1.keyFromPublic(publicKey, 'hex');
|
|
210
|
+
const pubPoint = key.getPublic();
|
|
211
|
+
return Object.assign(Object.assign({ alg: 'ES256' }, (use !== undefined && { use })), { kty: types_1.KeyType.EC, crv: types_1.KeyCurve.P_256, x: (0, exports.hex2base64url)(pubPoint.getX().toString('hex')), y: (0, exports.hex2base64url)(pubPoint.getY().toString('hex')) });
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Generates a JWK from an Ed25519/X25519 public key
|
|
215
|
+
* @param publicKeyHex Ed25519/X25519 public key in hex
|
|
216
|
+
* @param use The use for the key
|
|
217
|
+
* @return The JWK
|
|
218
|
+
*/
|
|
219
|
+
const toEd25519OrX25519Jwk = (publicKeyHex, opts) => {
|
|
220
|
+
var _a;
|
|
221
|
+
assertProperKeyLength(publicKeyHex, 64);
|
|
222
|
+
const { use } = opts !== null && opts !== void 0 ? opts : {};
|
|
223
|
+
return Object.assign(Object.assign({ alg: 'EdDSA' }, (use !== undefined && { use })), { kty: types_1.KeyType.OKP, crv: (_a = opts === null || opts === void 0 ? void 0 : opts.crv) !== null && _a !== void 0 ? _a : types_1.KeyCurve.Ed25519, x: (0, exports.hex2base64url)(publicKeyHex.substr(0, 64)) });
|
|
224
|
+
};
|
|
225
|
+
const toRSAJwk = (publicKeyHex, opts) => {
|
|
226
|
+
var _a, _b, _c;
|
|
227
|
+
const { key } = opts !== null && opts !== void 0 ? opts : {};
|
|
228
|
+
// const publicKey = publicKeyHex
|
|
229
|
+
// assertProperKeyLength(publicKey, [2048, 3072, 4096])
|
|
230
|
+
if ((_a = key === null || key === void 0 ? void 0 : key.meta) === null || _a === void 0 ? void 0 : _a.publicKeyJwk) {
|
|
231
|
+
return key.meta.publicKeyJwk;
|
|
232
|
+
}
|
|
233
|
+
const publicKeyPEM = (_c = (_b = key === null || key === void 0 ? void 0 : key.meta) === null || _b === void 0 ? void 0 : _b.publicKeyPEM) !== null && _c !== void 0 ? _c : (0, x509_1.hexToPEM)(publicKeyHex, 'public');
|
|
234
|
+
return (0, x509_1.PEMToJwk)(publicKeyPEM, 'public');
|
|
235
|
+
};
|
|
236
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAmD;AACnD,gDAA8E;AAI9E,wDAA+B;AAC/B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,IAAI,CAAC,YAA0B,CAAA;KAC3C;IAED,MAAM,YAAY,GAAG,MAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,0CAAE,YAAY,mCAAI,IAAA,eAAQ,EAAC,YAAY,EAAE,QAAQ,CAAC,CAAA;IAChF,OAAO,IAAA,eAAQ,EAAC,YAAY,EAAE,QAAQ,CAAe,CAAA;AACvD,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides `did:jwk` {@link @veramo/did-provider-jwk#JwkDIDProvider | identifier provider }
|
|
3
|
+
* for the {@link @veramo/did-manager#DIDManager}
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
*/
|
|
7
|
+
export * from './x509';
|
|
8
|
+
export * from './functions';
|
|
9
|
+
export * from './jwk-jcs';
|
|
10
|
+
export * from './types';
|
|
11
|
+
export * from './x509/x509-utils';
|
|
12
|
+
export * from './digest-methods';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/**
|
|
18
|
+
* Provides `did:jwk` {@link @veramo/did-provider-jwk#JwkDIDProvider | identifier provider }
|
|
19
|
+
* for the {@link @veramo/did-manager#DIDManager}
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
*/
|
|
23
|
+
__exportStar(require("./x509"), exports);
|
|
24
|
+
__exportStar(require("./functions"), exports);
|
|
25
|
+
__exportStar(require("./jwk-jcs"), exports);
|
|
26
|
+
__exportStar(require("./types"), exports);
|
|
27
|
+
__exportStar(require("./x509/x509-utils"), exports);
|
|
28
|
+
__exportStar(require("./digest-methods"), exports);
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;GAKG;AACH,yCAAsB;AACtB,8CAA2B;AAC3B,4CAAyB;AACzB,0CAAuB;AACvB,oDAAiC;AACjC,mDAAgC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ByteView } from 'multiformats/codecs/interface';
|
|
2
|
+
import type { JsonWebKey } from 'did-resolver';
|
|
3
|
+
/**
|
|
4
|
+
* Encodes a JWK into a Uint8Array. Only the required JWK members are encoded.
|
|
5
|
+
*
|
|
6
|
+
* @see https://www.rfc-editor.org/rfc/rfc7518#section-6
|
|
7
|
+
* @see https://www.rfc-editor.org/rfc/rfc8037#section-2
|
|
8
|
+
* @see https://github.com/panva/jose/blob/3b8aa47b92d07a711bf5c3125276cc9a011794a4/src/jwk/thumbprint.ts#L37
|
|
9
|
+
*
|
|
10
|
+
* @param jwk - JSON Web Key.
|
|
11
|
+
* @returns Uint8Array-encoded JWK.
|
|
12
|
+
*/
|
|
13
|
+
export declare function jwkJcsEncode(jwk: unknown): Uint8Array;
|
|
14
|
+
/**
|
|
15
|
+
* Decodes an array of bytes into a JWK. Throws an error if the JWK is not valid.
|
|
16
|
+
*
|
|
17
|
+
* @param bytes - The array of bytes to decode.
|
|
18
|
+
* @returns The corresponding JSON Web Key.
|
|
19
|
+
*/
|
|
20
|
+
export declare function jwkJcsDecode(bytes: ByteView<JsonWebKey>): JsonWebKey;
|
|
21
|
+
export declare function jcsCanonicalize(object: any): string;
|
|
22
|
+
//# sourceMappingURL=jwk-jcs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwk-jcs.d.ts","sourceRoot":"","sources":["../src/jwk-jcs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAuF9C;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,CAIrD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,UAAU,CAOpE;AAGD,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,UAsD1C"}
|