@atproto/crypto 0.4.5 → 0.5.0-next.0
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/CHANGELOG.md +14 -0
- package/LICENSE.txt +1 -1
- package/dist/const.js +6 -9
- package/dist/const.js.map +1 -1
- package/dist/did.js +15 -55
- package/dist/did.js.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -28
- package/dist/index.js.map +1 -1
- package/dist/multibase.js +3 -41
- package/dist/multibase.js.map +1 -1
- package/dist/p256/encoding.js +5 -10
- package/dist/p256/encoding.js.map +1 -1
- package/dist/p256/keypair.d.ts +1 -1
- package/dist/p256/keypair.d.ts.map +1 -1
- package/dist/p256/keypair.js +15 -73
- package/dist/p256/keypair.js.map +1 -1
- package/dist/p256/operations.d.ts +1 -1
- package/dist/p256/operations.d.ts.map +1 -1
- package/dist/p256/operations.js +16 -22
- package/dist/p256/operations.js.map +1 -1
- package/dist/p256/plugin.d.ts +1 -1
- package/dist/p256/plugin.d.ts.map +1 -1
- package/dist/p256/plugin.js +9 -12
- package/dist/p256/plugin.js.map +1 -1
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +3 -6
- package/dist/plugins.js.map +1 -1
- package/dist/random.d.ts +1 -2
- package/dist/random.d.ts.map +1 -1
- package/dist/random.js +8 -46
- package/dist/random.js.map +1 -1
- package/dist/secp256k1/encoding.js +5 -10
- package/dist/secp256k1/encoding.js.map +1 -1
- package/dist/secp256k1/keypair.d.ts +1 -1
- package/dist/secp256k1/keypair.d.ts.map +1 -1
- package/dist/secp256k1/keypair.js +15 -73
- package/dist/secp256k1/keypair.js.map +1 -1
- package/dist/secp256k1/operations.d.ts +1 -1
- package/dist/secp256k1/operations.d.ts.map +1 -1
- package/dist/secp256k1/operations.js +15 -54
- package/dist/secp256k1/operations.js.map +1 -1
- package/dist/secp256k1/plugin.d.ts +1 -1
- package/dist/secp256k1/plugin.d.ts.map +1 -1
- package/dist/secp256k1/plugin.js +9 -12
- package/dist/secp256k1/plugin.js.map +1 -1
- package/dist/sha.js +5 -43
- package/dist/sha.js.map +1 -1
- package/dist/types.js +1 -2
- package/dist/utils.js +9 -48
- package/dist/utils.js.map +1 -1
- package/dist/verify.d.ts +1 -1
- package/dist/verify.d.ts.map +1 -1
- package/dist/verify.js +8 -46
- package/dist/verify.js.map +1 -1
- package/{jest.config.js → jest.config.cjs} +8 -1
- package/package.json +14 -9
- package/src/did.ts +3 -3
- package/src/index.ts +12 -12
- package/src/p256/keypair.ts +3 -3
- package/src/p256/operations.ts +3 -3
- package/src/p256/plugin.ts +4 -4
- package/src/plugins.ts +2 -2
- package/src/random.ts +4 -2
- package/src/secp256k1/keypair.ts +3 -3
- package/src/secp256k1/operations.ts +3 -3
- package/src/secp256k1/plugin.ts +4 -4
- package/src/utils.ts +1 -1
- package/src/verify.ts +3 -3
- package/tests/did.test.ts +13 -4
- package/tests/key-compression.test.ts +5 -5
- package/tests/keypairs.test.ts +5 -5
- package/tests/random.test.ts +1 -1
- package/tests/signatures.test.ts +9 -7
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.tests.tsbuildinfo +0 -1
package/dist/utils.js
CHANGED
|
@@ -1,57 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.hasPrefix = exports.extractPrefixedBytes = exports.extractMultikey = void 0;
|
|
37
|
-
const uint8arrays = __importStar(require("uint8arrays"));
|
|
38
|
-
const const_1 = require("./const");
|
|
39
|
-
const extractMultikey = (did) => {
|
|
40
|
-
if (!did.startsWith(const_1.DID_KEY_PREFIX)) {
|
|
1
|
+
import * as uint8arrays from 'uint8arrays';
|
|
2
|
+
import { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const.js';
|
|
3
|
+
export const extractMultikey = (did) => {
|
|
4
|
+
if (!did.startsWith(DID_KEY_PREFIX)) {
|
|
41
5
|
throw new Error(`Incorrect prefix for did:key: ${did}`);
|
|
42
6
|
}
|
|
43
|
-
return did.slice(
|
|
7
|
+
return did.slice(DID_KEY_PREFIX.length);
|
|
44
8
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (!multikey.startsWith(const_1.BASE58_MULTIBASE_PREFIX)) {
|
|
9
|
+
export const extractPrefixedBytes = (multikey) => {
|
|
10
|
+
if (!multikey.startsWith(BASE58_MULTIBASE_PREFIX)) {
|
|
48
11
|
throw new Error(`Incorrect prefix for multikey: ${multikey}`);
|
|
49
12
|
}
|
|
50
|
-
return uint8arrays.fromString(multikey.slice(
|
|
13
|
+
return uint8arrays.fromString(multikey.slice(BASE58_MULTIBASE_PREFIX.length), 'base58btc');
|
|
51
14
|
};
|
|
52
|
-
|
|
53
|
-
const hasPrefix = (bytes, prefix) => {
|
|
15
|
+
export const hasPrefix = (bytes, prefix) => {
|
|
54
16
|
return uint8arrays.equals(prefix, bytes.subarray(0, prefix.byteLength));
|
|
55
17
|
};
|
|
56
|
-
exports.hasPrefix = hasPrefix;
|
|
57
18
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEpE,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAW,EAAU,EAAE;IACrD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,iCAAiC,GAAG,EAAE,CAAC,CAAA;IACzD,CAAC;IACD,OAAO,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;AACzC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,QAAgB,EAAc,EAAE;IACnE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,uBAAuB,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,kCAAkC,QAAQ,EAAE,CAAC,CAAA;IAC/D,CAAC;IACD,OAAO,WAAW,CAAC,UAAU,CAC3B,QAAQ,CAAC,KAAK,CAAC,uBAAuB,CAAC,MAAM,CAAC,EAC9C,WAAW,CACZ,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAiB,EAAE,MAAkB,EAAW,EAAE;IAC1E,OAAO,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAA;AACzE,CAAC,CAAA","sourcesContent":["import * as uint8arrays from 'uint8arrays'\nimport { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const.js'\n\nexport const extractMultikey = (did: string): string => {\n if (!did.startsWith(DID_KEY_PREFIX)) {\n throw new Error(`Incorrect prefix for did:key: ${did}`)\n }\n return did.slice(DID_KEY_PREFIX.length)\n}\n\nexport const extractPrefixedBytes = (multikey: string): Uint8Array => {\n if (!multikey.startsWith(BASE58_MULTIBASE_PREFIX)) {\n throw new Error(`Incorrect prefix for multikey: ${multikey}`)\n }\n return uint8arrays.fromString(\n multikey.slice(BASE58_MULTIBASE_PREFIX.length),\n 'base58btc',\n )\n}\n\nexport const hasPrefix = (bytes: Uint8Array, prefix: Uint8Array): boolean => {\n return uint8arrays.equals(prefix, bytes.subarray(0, prefix.byteLength))\n}\n"]}
|
package/dist/verify.d.ts
CHANGED
package/dist/verify.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE1C,eAAO,MAAM,eAAe,GAC1B,QAAQ,MAAM,EACd,MAAM,UAAU,EAChB,KAAK,UAAU,EACf,OAAO,aAAa,GAAG;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,KACA,OAAO,CAAC,OAAO,CAUjB,CAAA;AAED,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,MAAM,EACd,MAAM,MAAM,EACZ,KAAK,MAAM,EACX,OAAO,aAAa,KACnB,OAAO,CAAC,OAAO,CAIjB,CAAA"}
|
package/dist/verify.js
CHANGED
|
@@ -1,58 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.verifySignatureUtf8 = exports.verifySignature = void 0;
|
|
37
|
-
const uint8arrays = __importStar(require("uint8arrays"));
|
|
38
|
-
const did_1 = require("./did");
|
|
39
|
-
const plugins_1 = require("./plugins");
|
|
40
|
-
const verifySignature = (didKey, data, sig, opts) => {
|
|
41
|
-
const parsed = (0, did_1.parseDidKey)(didKey);
|
|
1
|
+
import * as uint8arrays from 'uint8arrays';
|
|
2
|
+
import { parseDidKey } from './did.js';
|
|
3
|
+
import { plugins } from './plugins.js';
|
|
4
|
+
export const verifySignature = (didKey, data, sig, opts) => {
|
|
5
|
+
const parsed = parseDidKey(didKey);
|
|
42
6
|
if (opts?.jwtAlg && opts.jwtAlg !== parsed.jwtAlg) {
|
|
43
7
|
throw new Error(`Expected key alg ${opts.jwtAlg}, got ${parsed.jwtAlg}`);
|
|
44
8
|
}
|
|
45
|
-
const plugin =
|
|
9
|
+
const plugin = plugins.find((p) => p.jwtAlg === parsed.jwtAlg);
|
|
46
10
|
if (!plugin) {
|
|
47
11
|
throw new Error(`Unsupported signature alg: ${parsed.jwtAlg}`);
|
|
48
12
|
}
|
|
49
13
|
return plugin.verifySignature(didKey, data, sig, opts);
|
|
50
14
|
};
|
|
51
|
-
|
|
52
|
-
const verifySignatureUtf8 = async (didKey, data, sig, opts) => {
|
|
15
|
+
export const verifySignatureUtf8 = async (didKey, data, sig, opts) => {
|
|
53
16
|
const dataBytes = uint8arrays.fromString(data, 'utf8');
|
|
54
17
|
const sigBytes = uint8arrays.fromString(sig, 'base64url');
|
|
55
|
-
return
|
|
18
|
+
return verifySignature(didKey, dataBytes, sigBytes, opts);
|
|
56
19
|
};
|
|
57
|
-
exports.verifySignatureUtf8 = verifySignatureUtf8;
|
|
58
20
|
//# sourceMappingURL=verify.js.map
|
package/dist/verify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,MAAc,EACd,IAAgB,EAChB,GAAe,EACf,IAEC,EACiB,EAAE;IACpB,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;IAClC,IAAI,IAAI,EAAE,MAAM,IAAI,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,oBAAoB,IAAI,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;IAC1E,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAA;IAC9D,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,8BAA8B,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;IAChE,CAAC;IACD,OAAO,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;AACxD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,MAAc,EACd,IAAY,EACZ,GAAW,EACX,IAAoB,EACF,EAAE;IACpB,MAAM,SAAS,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACtD,MAAM,QAAQ,GAAG,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;IACzD,OAAO,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;AAC3D,CAAC,CAAA","sourcesContent":["import * as uint8arrays from 'uint8arrays'\nimport { parseDidKey } from './did.js'\nimport { plugins } from './plugins.js'\nimport { VerifyOptions } from './types.js'\n\nexport const verifySignature = (\n didKey: string,\n data: Uint8Array,\n sig: Uint8Array,\n opts?: VerifyOptions & {\n jwtAlg?: string\n },\n): Promise<boolean> => {\n const parsed = parseDidKey(didKey)\n if (opts?.jwtAlg && opts.jwtAlg !== parsed.jwtAlg) {\n throw new Error(`Expected key alg ${opts.jwtAlg}, got ${parsed.jwtAlg}`)\n }\n const plugin = plugins.find((p) => p.jwtAlg === parsed.jwtAlg)\n if (!plugin) {\n throw new Error(`Unsupported signature alg: ${parsed.jwtAlg}`)\n }\n return plugin.verifySignature(didKey, data, sig, opts)\n}\n\nexport const verifySignatureUtf8 = async (\n didKey: string,\n data: string,\n sig: string,\n opts?: VerifyOptions,\n): Promise<boolean> => {\n const dataBytes = uint8arrays.fromString(data, 'utf8')\n const sigBytes = uint8arrays.fromString(sig, 'base64url')\n return verifySignature(didKey, dataBytes, sigBytes, opts)\n}\n"]}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
/** @type {import('jest').Config} */
|
|
2
2
|
module.exports = {
|
|
3
3
|
displayName: 'Crypto',
|
|
4
|
-
transform: {
|
|
4
|
+
transform: {
|
|
5
|
+
'^.+\\.(t|j)s$': [
|
|
6
|
+
'@swc/jest',
|
|
7
|
+
{ jsc: { transform: {} }, module: { type: 'es6' } },
|
|
8
|
+
],
|
|
9
|
+
},
|
|
10
|
+
extensionsToTreatAsEsm: ['.ts'],
|
|
11
|
+
transformIgnorePatterns: [],
|
|
5
12
|
setupFiles: ['<rootDir>/../../jest.setup.ts'],
|
|
6
13
|
moduleNameMapper: { '^(\\.\\.?\\/.+)\\.js$': ['$1.ts', '$1.js'] },
|
|
7
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/crypto",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-next.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Library for cryptographic keys and signing in atproto",
|
|
6
6
|
"keywords": [
|
|
@@ -13,23 +13,28 @@
|
|
|
13
13
|
"url": "https://github.com/bluesky-social/atproto",
|
|
14
14
|
"directory": "packages/crypto"
|
|
15
15
|
},
|
|
16
|
-
"main": "dist/index.js",
|
|
17
|
-
"types": "dist/index.d.ts",
|
|
18
16
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
17
|
+
"node": ">=22"
|
|
20
18
|
},
|
|
21
19
|
"dependencies": {
|
|
22
20
|
"@noble/curves": "^1.7.0",
|
|
23
21
|
"@noble/hashes": "^1.6.1",
|
|
24
|
-
"uint8arrays": "
|
|
22
|
+
"uint8arrays": "^5.0.0"
|
|
25
23
|
},
|
|
26
24
|
"devDependencies": {
|
|
27
|
-
"jest": "^
|
|
28
|
-
"typescript": "^
|
|
29
|
-
"@atproto/common": "^0.
|
|
25
|
+
"jest": "^30.0.0",
|
|
26
|
+
"typescript": "^6.0.3",
|
|
27
|
+
"@atproto/common": "^0.6.0-next.0"
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
}
|
|
30
35
|
},
|
|
31
36
|
"scripts": {
|
|
32
|
-
"test": "jest
|
|
37
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
33
38
|
"build": "tsc --build tsconfig.build.json"
|
|
34
39
|
}
|
|
35
40
|
}
|
package/src/did.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as uint8arrays from 'uint8arrays'
|
|
2
|
-
import { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const'
|
|
3
|
-
import { plugins } from './plugins'
|
|
4
|
-
import { extractMultikey, extractPrefixedBytes, hasPrefix } from './utils'
|
|
2
|
+
import { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const.js'
|
|
3
|
+
import { plugins } from './plugins.js'
|
|
4
|
+
import { extractMultikey, extractPrefixedBytes, hasPrefix } from './utils.js'
|
|
5
5
|
|
|
6
6
|
export type ParsedMultikey = {
|
|
7
7
|
jwtAlg: string
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export * from './const'
|
|
2
|
-
export * from './did'
|
|
3
|
-
export * from './multibase'
|
|
4
|
-
export * from './random'
|
|
5
|
-
export * from './sha'
|
|
6
|
-
export * from './types'
|
|
7
|
-
export * from './verify'
|
|
8
|
-
export * from './utils'
|
|
1
|
+
export * from './const.js'
|
|
2
|
+
export * from './did.js'
|
|
3
|
+
export * from './multibase.js'
|
|
4
|
+
export * from './random.js'
|
|
5
|
+
export * from './sha.js'
|
|
6
|
+
export * from './types.js'
|
|
7
|
+
export * from './verify.js'
|
|
8
|
+
export * from './utils.js'
|
|
9
9
|
|
|
10
|
-
export * from './p256/keypair'
|
|
11
|
-
export * from './p256/plugin'
|
|
10
|
+
export * from './p256/keypair.js'
|
|
11
|
+
export * from './p256/plugin.js'
|
|
12
12
|
|
|
13
|
-
export * from './secp256k1/keypair'
|
|
14
|
-
export * from './secp256k1/plugin'
|
|
13
|
+
export * from './secp256k1/keypair.js'
|
|
14
|
+
export * from './secp256k1/plugin.js'
|
package/src/p256/keypair.ts
CHANGED
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
toString as ui8ToString,
|
|
6
6
|
} from 'uint8arrays'
|
|
7
7
|
import { SupportedEncodings } from 'uint8arrays/to-string'
|
|
8
|
-
import { P256_JWT_ALG } from '../const'
|
|
9
|
-
import * as did from '../did'
|
|
10
|
-
import { Keypair } from '../types'
|
|
8
|
+
import { P256_JWT_ALG } from '../const.js'
|
|
9
|
+
import * as did from '../did.js'
|
|
10
|
+
import { Keypair } from '../types.js'
|
|
11
11
|
|
|
12
12
|
export type P256KeypairOptions = {
|
|
13
13
|
exportable: boolean
|
package/src/p256/operations.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { p256 } from '@noble/curves/p256'
|
|
2
2
|
import { sha256 } from '@noble/hashes/sha256'
|
|
3
3
|
import { equals as ui8equals } from 'uint8arrays'
|
|
4
|
-
import { P256_DID_PREFIX } from '../const'
|
|
5
|
-
import { VerifyOptions } from '../types'
|
|
6
|
-
import { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils'
|
|
4
|
+
import { P256_DID_PREFIX } from '../const.js'
|
|
5
|
+
import { VerifyOptions } from '../types.js'
|
|
6
|
+
import { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils.js'
|
|
7
7
|
|
|
8
8
|
export const verifyDidSig = async (
|
|
9
9
|
did: string,
|
package/src/p256/plugin.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { P256_DID_PREFIX, P256_JWT_ALG } from '../const'
|
|
2
|
-
import { DidKeyPlugin } from '../types'
|
|
3
|
-
import { compressPubkey, decompressPubkey } from './encoding'
|
|
4
|
-
import { verifyDidSig } from './operations'
|
|
1
|
+
import { P256_DID_PREFIX, P256_JWT_ALG } from '../const.js'
|
|
2
|
+
import { DidKeyPlugin } from '../types.js'
|
|
3
|
+
import { compressPubkey, decompressPubkey } from './encoding.js'
|
|
4
|
+
import { verifyDidSig } from './operations.js'
|
|
5
5
|
|
|
6
6
|
export const p256Plugin: DidKeyPlugin = {
|
|
7
7
|
prefix: P256_DID_PREFIX,
|
package/src/plugins.ts
CHANGED
package/src/random.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as noble from '@noble/hashes/utils'
|
|
2
2
|
import * as uint8arrays from 'uint8arrays'
|
|
3
3
|
import { SupportedEncodings } from 'uint8arrays/to-string'
|
|
4
|
-
import { sha256 } from './sha'
|
|
4
|
+
import { sha256 } from './sha.js'
|
|
5
5
|
|
|
6
|
-
export const randomBytes = noble.randomBytes
|
|
6
|
+
export const randomBytes = noble.randomBytes as (
|
|
7
|
+
bytesLength?: number,
|
|
8
|
+
) => Uint8Array<ArrayBuffer>
|
|
7
9
|
|
|
8
10
|
export const randomStr = (
|
|
9
11
|
byteLength: number,
|
package/src/secp256k1/keypair.ts
CHANGED
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
toString as ui8ToString,
|
|
6
6
|
} from 'uint8arrays'
|
|
7
7
|
import { SupportedEncodings } from 'uint8arrays/to-string'
|
|
8
|
-
import { SECP256K1_JWT_ALG } from '../const'
|
|
9
|
-
import * as did from '../did'
|
|
10
|
-
import { Keypair } from '../types'
|
|
8
|
+
import { SECP256K1_JWT_ALG } from '../const.js'
|
|
9
|
+
import * as did from '../did.js'
|
|
10
|
+
import { Keypair } from '../types.js'
|
|
11
11
|
|
|
12
12
|
export type Secp256k1KeypairOptions = {
|
|
13
13
|
exportable: boolean
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { secp256k1 as k256 } from '@noble/curves/secp256k1'
|
|
2
2
|
import { sha256 } from '@noble/hashes/sha256'
|
|
3
3
|
import * as ui8 from 'uint8arrays'
|
|
4
|
-
import { SECP256K1_DID_PREFIX } from '../const'
|
|
5
|
-
import { VerifyOptions } from '../types'
|
|
6
|
-
import { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils'
|
|
4
|
+
import { SECP256K1_DID_PREFIX } from '../const.js'
|
|
5
|
+
import { VerifyOptions } from '../types.js'
|
|
6
|
+
import { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils.js'
|
|
7
7
|
|
|
8
8
|
export const verifyDidSig = async (
|
|
9
9
|
did: string,
|
package/src/secp256k1/plugin.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { SECP256K1_DID_PREFIX, SECP256K1_JWT_ALG } from '../const'
|
|
2
|
-
import { DidKeyPlugin } from '../types'
|
|
3
|
-
import { compressPubkey, decompressPubkey } from './encoding'
|
|
4
|
-
import { verifyDidSig } from './operations'
|
|
1
|
+
import { SECP256K1_DID_PREFIX, SECP256K1_JWT_ALG } from '../const.js'
|
|
2
|
+
import { DidKeyPlugin } from '../types.js'
|
|
3
|
+
import { compressPubkey, decompressPubkey } from './encoding.js'
|
|
4
|
+
import { verifyDidSig } from './operations.js'
|
|
5
5
|
|
|
6
6
|
export const secp256k1Plugin: DidKeyPlugin = {
|
|
7
7
|
prefix: SECP256K1_DID_PREFIX,
|
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as uint8arrays from 'uint8arrays'
|
|
2
|
-
import { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const'
|
|
2
|
+
import { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const.js'
|
|
3
3
|
|
|
4
4
|
export const extractMultikey = (did: string): string => {
|
|
5
5
|
if (!did.startsWith(DID_KEY_PREFIX)) {
|
package/src/verify.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as uint8arrays from 'uint8arrays'
|
|
2
|
-
import { parseDidKey } from './did'
|
|
3
|
-
import { plugins } from './plugins'
|
|
4
|
-
import { VerifyOptions } from './types'
|
|
2
|
+
import { parseDidKey } from './did.js'
|
|
3
|
+
import { plugins } from './plugins.js'
|
|
4
|
+
import { VerifyOptions } from './types.js'
|
|
5
5
|
|
|
6
6
|
export const verifySignature = (
|
|
7
7
|
didKey: string,
|
package/tests/did.test.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as uint8arrays from 'uint8arrays'
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import * as did from '../src/did.js'
|
|
3
|
+
import { P256Keypair, Secp256k1Keypair } from '../src/index.js'
|
|
4
|
+
import { decompressPubkey as p256Decompress } from '../src/p256/encoding.js'
|
|
5
|
+
import { decompressPubkey as secp256k1Decompress } from '../src/secp256k1/encoding.js'
|
|
4
6
|
|
|
5
7
|
describe('secp256k1 did:key', () => {
|
|
6
8
|
it('derives the correct DID from the privatekey', async () => {
|
|
@@ -18,7 +20,12 @@ describe('secp256k1 did:key', () => {
|
|
|
18
20
|
expect(didKey).toEqual(vector.id)
|
|
19
21
|
const { jwtAlg, keyBytes } = did.parseDidKey(didKey)
|
|
20
22
|
expect(jwtAlg).toBe('ES256K')
|
|
21
|
-
expect(
|
|
23
|
+
expect(
|
|
24
|
+
uint8arrays.equals(
|
|
25
|
+
keyBytes,
|
|
26
|
+
secp256k1Decompress(keypair.publicKeyBytes()),
|
|
27
|
+
),
|
|
28
|
+
).toBeTruthy()
|
|
22
29
|
}
|
|
23
30
|
})
|
|
24
31
|
})
|
|
@@ -41,7 +48,9 @@ describe('P-256 did:key', () => {
|
|
|
41
48
|
expect(didKey).toEqual(vector.id)
|
|
42
49
|
const { jwtAlg, keyBytes } = did.parseDidKey(didKey)
|
|
43
50
|
expect(jwtAlg).toBe('ES256')
|
|
44
|
-
expect(
|
|
51
|
+
expect(
|
|
52
|
+
uint8arrays.equals(keyBytes, p256Decompress(keypair.publicKeyBytes())),
|
|
53
|
+
).toBeTruthy()
|
|
45
54
|
}
|
|
46
55
|
})
|
|
47
56
|
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as did from '../src/did'
|
|
2
|
-
import * as p256Encoding from '../src/p256/encoding'
|
|
3
|
-
import { P256Keypair } from '../src/p256/keypair'
|
|
4
|
-
import * as secpEncoding from '../src/secp256k1/encoding'
|
|
5
|
-
import { Secp256k1Keypair } from '../src/secp256k1/keypair'
|
|
1
|
+
import * as did from '../src/did.js'
|
|
2
|
+
import * as p256Encoding from '../src/p256/encoding.js'
|
|
3
|
+
import { P256Keypair } from '../src/p256/keypair.js'
|
|
4
|
+
import * as secpEncoding from '../src/secp256k1/encoding.js'
|
|
5
|
+
import { Secp256k1Keypair } from '../src/secp256k1/keypair.js'
|
|
6
6
|
|
|
7
7
|
describe('public key compression', () => {
|
|
8
8
|
describe('secp256k1', () => {
|
package/tests/keypairs.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { randomBytes } from '../src'
|
|
2
|
-
import { P256Keypair } from '../src/p256/keypair'
|
|
3
|
-
import * as p256 from '../src/p256/operations'
|
|
4
|
-
import { Secp256k1Keypair } from '../src/secp256k1/keypair'
|
|
5
|
-
import * as secp from '../src/secp256k1/operations'
|
|
1
|
+
import { randomBytes } from '../src/index.js'
|
|
2
|
+
import { P256Keypair } from '../src/p256/keypair.js'
|
|
3
|
+
import * as p256 from '../src/p256/operations.js'
|
|
4
|
+
import { Secp256k1Keypair } from '../src/secp256k1/keypair.js'
|
|
5
|
+
import * as secp from '../src/secp256k1/operations.js'
|
|
6
6
|
|
|
7
7
|
describe('keypairs', () => {
|
|
8
8
|
describe('secp256k1', () => {
|
package/tests/random.test.ts
CHANGED
package/tests/signatures.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/* eslint-disable import/no-deprecated */
|
|
2
|
-
|
|
3
1
|
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
4
|
import { p256 as nobleP256 } from '@noble/curves/p256'
|
|
5
5
|
import { secp256k1 as nobleK256 } from '@noble/curves/secp256k1'
|
|
6
6
|
import * as uint8arrays from 'uint8arrays'
|
|
@@ -12,11 +12,13 @@ import {
|
|
|
12
12
|
multibaseToBytes,
|
|
13
13
|
parseDidKey,
|
|
14
14
|
sha256,
|
|
15
|
-
} from '../src'
|
|
16
|
-
import { P256Keypair } from '../src/p256/keypair'
|
|
17
|
-
import * as p256 from '../src/p256/operations'
|
|
18
|
-
import { Secp256k1Keypair } from '../src/secp256k1/keypair'
|
|
19
|
-
import * as secp from '../src/secp256k1/operations'
|
|
15
|
+
} from '../src/index.js'
|
|
16
|
+
import { P256Keypair } from '../src/p256/keypair.js'
|
|
17
|
+
import * as p256 from '../src/p256/operations.js'
|
|
18
|
+
import { Secp256k1Keypair } from '../src/secp256k1/keypair.js'
|
|
19
|
+
import * as secp from '../src/secp256k1/operations.js'
|
|
20
|
+
|
|
21
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
20
22
|
|
|
21
23
|
describe('signatures', () => {
|
|
22
24
|
let vectors: TestVector[]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/const.ts","./src/did.ts","./src/index.ts","./src/multibase.ts","./src/plugins.ts","./src/random.ts","./src/sha.ts","./src/types.ts","./src/utils.ts","./src/verify.ts","./src/p256/encoding.ts","./src/p256/keypair.ts","./src/p256/operations.ts","./src/p256/plugin.ts","./src/secp256k1/encoding.ts","./src/secp256k1/keypair.ts","./src/secp256k1/operations.ts","./src/secp256k1/plugin.ts"],"version":"
|
|
1
|
+
{"root":["./src/const.ts","./src/did.ts","./src/index.ts","./src/multibase.ts","./src/plugins.ts","./src/random.ts","./src/sha.ts","./src/types.ts","./src/utils.ts","./src/verify.ts","./src/p256/encoding.ts","./src/p256/keypair.ts","./src/p256/operations.ts","./src/p256/plugin.ts","./src/secp256k1/encoding.ts","./src/secp256k1/keypair.ts","./src/secp256k1/operations.ts","./src/secp256k1/plugin.ts"],"version":"6.0.3"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"root":["./tests/did.test.ts","./tests/key-compression.test.ts","./tests/keypairs.test.ts","./tests/random.test.ts","./tests/signatures.test.ts"],"version":"5.8.3"}
|