@atproto/crypto 0.4.4 → 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.
Files changed (89) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/LICENSE.txt +1 -1
  3. package/dist/const.d.ts +2 -2
  4. package/dist/const.d.ts.map +1 -1
  5. package/dist/const.js +6 -9
  6. package/dist/const.js.map +1 -1
  7. package/dist/did.d.ts +1 -1
  8. package/dist/did.d.ts.map +1 -1
  9. package/dist/did.js +16 -46
  10. package/dist/did.js.map +1 -1
  11. package/dist/index.d.ts +12 -12
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +12 -28
  14. package/dist/index.js.map +1 -1
  15. package/dist/multibase.d.ts.map +1 -1
  16. package/dist/multibase.js +3 -31
  17. package/dist/multibase.js.map +1 -1
  18. package/dist/p256/encoding.d.ts.map +1 -1
  19. package/dist/p256/encoding.js +5 -10
  20. package/dist/p256/encoding.js.map +1 -1
  21. package/dist/p256/keypair.d.ts +1 -1
  22. package/dist/p256/keypair.d.ts.map +1 -1
  23. package/dist/p256/keypair.js +15 -63
  24. package/dist/p256/keypair.js.map +1 -1
  25. package/dist/p256/operations.d.ts +1 -1
  26. package/dist/p256/operations.d.ts.map +1 -1
  27. package/dist/p256/operations.js +16 -22
  28. package/dist/p256/operations.js.map +1 -1
  29. package/dist/p256/plugin.d.ts +1 -1
  30. package/dist/p256/plugin.d.ts.map +1 -1
  31. package/dist/p256/plugin.js +9 -12
  32. package/dist/p256/plugin.js.map +1 -1
  33. package/dist/plugins.d.ts +1 -1
  34. package/dist/plugins.d.ts.map +1 -1
  35. package/dist/plugins.js +3 -6
  36. package/dist/plugins.js.map +1 -1
  37. package/dist/random.d.ts +1 -2
  38. package/dist/random.d.ts.map +1 -1
  39. package/dist/random.js +8 -36
  40. package/dist/random.js.map +1 -1
  41. package/dist/secp256k1/encoding.d.ts.map +1 -1
  42. package/dist/secp256k1/encoding.js +5 -10
  43. package/dist/secp256k1/encoding.js.map +1 -1
  44. package/dist/secp256k1/keypair.d.ts +1 -1
  45. package/dist/secp256k1/keypair.d.ts.map +1 -1
  46. package/dist/secp256k1/keypair.js +15 -63
  47. package/dist/secp256k1/keypair.js.map +1 -1
  48. package/dist/secp256k1/operations.d.ts +1 -1
  49. package/dist/secp256k1/operations.d.ts.map +1 -1
  50. package/dist/secp256k1/operations.js +15 -44
  51. package/dist/secp256k1/operations.js.map +1 -1
  52. package/dist/secp256k1/plugin.d.ts +1 -1
  53. package/dist/secp256k1/plugin.d.ts.map +1 -1
  54. package/dist/secp256k1/plugin.js +9 -12
  55. package/dist/secp256k1/plugin.js.map +1 -1
  56. package/dist/sha.d.ts.map +1 -1
  57. package/dist/sha.js +5 -33
  58. package/dist/sha.js.map +1 -1
  59. package/dist/types.js +1 -2
  60. package/dist/types.js.map +1 -1
  61. package/dist/utils.d.ts.map +1 -1
  62. package/dist/utils.js +9 -38
  63. package/dist/utils.js.map +1 -1
  64. package/dist/verify.d.ts +1 -1
  65. package/dist/verify.d.ts.map +1 -1
  66. package/dist/verify.js +8 -36
  67. package/dist/verify.js.map +1 -1
  68. package/jest.config.cjs +14 -0
  69. package/package.json +14 -9
  70. package/src/did.ts +8 -5
  71. package/src/index.ts +12 -12
  72. package/src/p256/keypair.ts +3 -3
  73. package/src/p256/operations.ts +3 -3
  74. package/src/p256/plugin.ts +4 -4
  75. package/src/plugins.ts +2 -2
  76. package/src/random.ts +4 -2
  77. package/src/secp256k1/keypair.ts +3 -3
  78. package/src/secp256k1/operations.ts +3 -3
  79. package/src/secp256k1/plugin.ts +4 -4
  80. package/src/utils.ts +1 -1
  81. package/src/verify.ts +3 -3
  82. package/tests/did.test.ts +13 -4
  83. package/tests/key-compression.test.ts +5 -5
  84. package/tests/keypairs.test.ts +5 -5
  85. package/tests/random.test.ts +2 -2
  86. package/tests/signatures.test.ts +9 -5
  87. package/tsconfig.build.tsbuildinfo +1 -1
  88. package/jest.config.js +0 -6
  89. package/tsconfig.tests.tsbuildinfo +0 -1
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA0C;AAC1C,mCAAiE;AAE1D,MAAM,eAAe,GAAG,CAAC,GAAW,EAAU,EAAE;IACrD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,sBAAc,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,iCAAiC,GAAG,EAAE,CAAC,CAAA;IACzD,CAAC;IACD,OAAO,GAAG,CAAC,KAAK,CAAC,sBAAc,CAAC,MAAM,CAAC,CAAA;AACzC,CAAC,CAAA;AALY,QAAA,eAAe,mBAK3B;AAEM,MAAM,oBAAoB,GAAG,CAAC,QAAgB,EAAc,EAAE;IACnE,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,+BAAuB,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,+BAAuB,CAAC,MAAM,CAAC,EAC9C,WAAW,CACZ,CAAA;AACH,CAAC,CAAA;AARY,QAAA,oBAAoB,wBAQhC;AAEM,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;AAFY,QAAA,SAAS,aAErB"}
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
@@ -1,4 +1,4 @@
1
- import { VerifyOptions } from './types';
1
+ import { VerifyOptions } from './types.js';
2
2
  export declare const verifySignature: (didKey: string, data: Uint8Array, sig: Uint8Array, opts?: VerifyOptions & {
3
3
  jwtAlg?: string;
4
4
  }) => Promise<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEvC,eAAO,MAAM,eAAe,WAClB,MAAM,QACR,UAAU,OACX,UAAU,SACR,aAAa,GAAG;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,KACA,OAAO,CAAC,OAAO,CAUjB,CAAA;AAED,eAAO,MAAM,mBAAmB,WACtB,MAAM,QACR,MAAM,OACP,MAAM,SACJ,aAAa,KACnB,OAAO,CAAC,OAAO,CAIjB,CAAA"}
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,48 +1,20 @@
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.verifySignatureUtf8 = exports.verifySignature = void 0;
27
- const uint8arrays = __importStar(require("uint8arrays"));
28
- const did_1 = require("./did");
29
- const plugins_1 = require("./plugins");
30
- const verifySignature = (didKey, data, sig, opts) => {
31
- 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);
32
6
  if (opts?.jwtAlg && opts.jwtAlg !== parsed.jwtAlg) {
33
7
  throw new Error(`Expected key alg ${opts.jwtAlg}, got ${parsed.jwtAlg}`);
34
8
  }
35
- const plugin = plugins_1.plugins.find((p) => p.jwtAlg === parsed.jwtAlg);
9
+ const plugin = plugins.find((p) => p.jwtAlg === parsed.jwtAlg);
36
10
  if (!plugin) {
37
11
  throw new Error(`Unsupported signature alg: ${parsed.jwtAlg}`);
38
12
  }
39
13
  return plugin.verifySignature(didKey, data, sig, opts);
40
14
  };
41
- exports.verifySignature = verifySignature;
42
- const verifySignatureUtf8 = async (didKey, data, sig, opts) => {
15
+ export const verifySignatureUtf8 = async (didKey, data, sig, opts) => {
43
16
  const dataBytes = uint8arrays.fromString(data, 'utf8');
44
17
  const sigBytes = uint8arrays.fromString(sig, 'base64url');
45
- return (0, exports.verifySignature)(didKey, dataBytes, sigBytes, opts);
18
+ return verifySignature(didKey, dataBytes, sigBytes, opts);
46
19
  };
47
- exports.verifySignatureUtf8 = verifySignatureUtf8;
48
20
  //# sourceMappingURL=verify.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"verify.js","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA0C;AAC1C,+BAAmC;AACnC,uCAAmC;AAG5B,MAAM,eAAe,GAAG,CAC7B,MAAc,EACd,IAAgB,EAChB,GAAe,EACf,IAEC,EACiB,EAAE;IACpB,MAAM,MAAM,GAAG,IAAA,iBAAW,EAAC,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,iBAAO,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;AAjBY,QAAA,eAAe,mBAiB3B;AAEM,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,IAAA,uBAAe,EAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;AAC3D,CAAC,CAAA;AATY,QAAA,mBAAmB,uBAS/B"}
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"]}
@@ -0,0 +1,14 @@
1
+ /** @type {import('jest').Config} */
2
+ module.exports = {
3
+ displayName: 'Crypto',
4
+ transform: {
5
+ '^.+\\.(t|j)s$': [
6
+ '@swc/jest',
7
+ { jsc: { transform: {} }, module: { type: 'es6' } },
8
+ ],
9
+ },
10
+ extensionsToTreatAsEsm: ['.ts'],
11
+ transformIgnorePatterns: [],
12
+ setupFiles: ['<rootDir>/../../jest.setup.ts'],
13
+ moduleNameMapper: { '^(\\.\\.?\\/.+)\\.js$': ['$1.ts', '$1.js'] },
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/crypto",
3
- "version": "0.4.4",
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": ">=18.7.0"
17
+ "node": ">=22"
20
18
  },
21
19
  "dependencies": {
22
20
  "@noble/curves": "^1.7.0",
23
21
  "@noble/hashes": "^1.6.1",
24
- "uint8arrays": "3.0.0"
22
+ "uint8arrays": "^5.0.0"
25
23
  },
26
24
  "devDependencies": {
27
- "jest": "^28.1.2",
28
- "typescript": "^5.6.3",
29
- "@atproto/common": "^0.4.8"
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
@@ -45,6 +45,9 @@ export const parseDidKey = (did: string): ParsedMultikey => {
45
45
  return parseMultikey(multikey)
46
46
  }
47
47
 
48
- export const formatDidKey = (jwtAlg: string, keyBytes: Uint8Array): string => {
49
- return DID_KEY_PREFIX + formatMultikey(jwtAlg, keyBytes)
48
+ export function formatDidKey(
49
+ jwtAlg: string,
50
+ keyBytes: Uint8Array,
51
+ ): `did:key:${string}` {
52
+ return `${DID_KEY_PREFIX}${formatMultikey(jwtAlg, keyBytes)}` as const
50
53
  }
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'
@@ -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
@@ -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,
@@ -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
@@ -1,4 +1,4 @@
1
- import { p256Plugin } from './p256/plugin'
2
- import { secp256k1Plugin } from './secp256k1/plugin'
1
+ import { p256Plugin } from './p256/plugin.js'
2
+ import { secp256k1Plugin } from './secp256k1/plugin.js'
3
3
 
4
4
  export const plugins = [p256Plugin, secp256k1Plugin]
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,
@@ -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,
@@ -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 { P256Keypair, Secp256k1Keypair } from '../src'
3
- import * as did from '../src/did'
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(uint8arrays.equals(keyBytes, keypair.publicKeyBytes())).toBeTruthy
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(uint8arrays.equals(keyBytes, keypair.publicKeyBytes())).toBeTruthy
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', () => {
@@ -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', () => {
@@ -1,4 +1,4 @@
1
- import { randomIntFromSeed } from '../src'
1
+ import { randomIntFromSeed } from '../src/index.js'
2
2
 
3
3
  describe('randomIntFromSeed()', () => {
4
4
  it('has good distribution for low bucket count.', async () => {
@@ -10,6 +10,6 @@ describe('randomIntFromSeed()', () => {
10
10
  }
11
11
  const [zero, one] = counts
12
12
  expect(zero + one).toEqual(10000)
13
- expect(Math.max(zero, one) / Math.min(zero, one)).toBeLessThan(1.05)
13
+ expect(Math.max(zero, one) / Math.min(zero, one)).toBeLessThan(1.1)
14
14
  })
15
15
  })
@@ -1,4 +1,6 @@
1
1
  import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
2
4
  import { p256 as nobleP256 } from '@noble/curves/p256'
3
5
  import { secp256k1 as nobleK256 } from '@noble/curves/secp256k1'
4
6
  import * as uint8arrays from 'uint8arrays'
@@ -10,11 +12,13 @@ import {
10
12
  multibaseToBytes,
11
13
  parseDidKey,
12
14
  sha256,
13
- } from '../src'
14
- import { P256Keypair } from '../src/p256/keypair'
15
- import * as p256 from '../src/p256/operations'
16
- import { Secp256k1Keypair } from '../src/secp256k1/keypair'
17
- 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))
18
22
 
19
23
  describe('signatures', () => {
20
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":"5.6.3"}
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"}
package/jest.config.js DELETED
@@ -1,6 +0,0 @@
1
- /** @type {import('jest').Config} */
2
- module.exports = {
3
- displayName: 'Crypto',
4
- transform: { '^.+\\.(t|j)s$': '@swc/jest' },
5
- setupFiles: ['<rootDir>/../../jest.setup.ts'],
6
- }
@@ -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.6.3"}