@atproto/crypto
Advanced tools
| /** @type {import('jest').Config} */ | ||
| module.exports = { | ||
| displayName: 'Crypto', | ||
| transform: { | ||
| '^.+\\.(t|j)s$': [ | ||
| '@swc/jest', | ||
| { jsc: { transform: {} }, module: { type: 'es6' } }, | ||
| ], | ||
| }, | ||
| extensionsToTreatAsEsm: ['.ts'], | ||
| transformIgnorePatterns: [], | ||
| setupFiles: ['<rootDir>/../../jest.setup.ts'], | ||
| moduleNameMapper: { '^(\\.\\.?\\/.+)\\.js$': ['$1.ts', '$1.js'] }, | ||
| } |
+14
-0
| # @atproto/crypto | ||
| ## 0.5.0-next.0 | ||
| ### Minor Changes | ||
| - [#4929](https://github.com/bluesky-social/atproto/pull/4929) [`bb7491c`](https://github.com/bluesky-social/atproto/commit/bb7491c29e06181e1d2f8cf6eb454f9bb8ab961b) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Drop support for Node.js 18 and 20. Node.js 22 is now the minimum supported version. Docker images now use Node.js 24. | ||
| - [#4943](https://github.com/bluesky-social/atproto/pull/4943) [`07ae5d4`](https://github.com/bluesky-social/atproto/commit/07ae5d4452df51e045e0239da7a04cf0bc154028) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Convert to pure ESM. All packages now ship `"type": "module"` with ES module output and Node16 module resolution. | ||
| Node.js 22's `require()` compatibility layer can still load these packages in CommonJS code. | ||
| - [#4930](https://github.com/bluesky-social/atproto/pull/4930) [`042df15`](https://github.com/bluesky-social/atproto/commit/042df15087c0e62cd1e715fcbf58852fab875af9) Thanks [@devinivy](https://github.com/devinivy)! - Build with TypeScript 6.0. Emitted `.d.ts` files now use TypeScript 6's stricter `Uint8Array<ArrayBuffer>` typing in places where Web/Node APIs require buffer-backed (not shared-memory) byte arrays. Consumers compiling against these types on older TypeScript should see no runtime impact, but may need to widen or cast in spots that previously relied on `Uint8Array` defaulting to `<ArrayBufferLike>`. | ||
| Internal: tsconfig `moduleResolution: "node"` is silenced via `ignoreDeprecations: "6.0"` for now; the proper migration to `node16`/`bundler` resolution is deferred. | ||
| ## 0.4.5 | ||
@@ -4,0 +18,0 @@ |
+6
-9
@@ -1,10 +0,7 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.SECP256K1_JWT_ALG = exports.P256_JWT_ALG = exports.DID_KEY_PREFIX = exports.BASE58_MULTIBASE_PREFIX = exports.SECP256K1_DID_PREFIX = exports.P256_DID_PREFIX = void 0; | ||
| exports.P256_DID_PREFIX = new Uint8Array([0x80, 0x24]); | ||
| exports.SECP256K1_DID_PREFIX = new Uint8Array([0xe7, 0x01]); | ||
| exports.BASE58_MULTIBASE_PREFIX = 'z'; | ||
| exports.DID_KEY_PREFIX = 'did:key:'; | ||
| exports.P256_JWT_ALG = 'ES256'; | ||
| exports.SECP256K1_JWT_ALG = 'ES256K'; | ||
| export const P256_DID_PREFIX = new Uint8Array([0x80, 0x24]); | ||
| export const SECP256K1_DID_PREFIX = new Uint8Array([0xe7, 0x01]); | ||
| export const BASE58_MULTIBASE_PREFIX = 'z'; | ||
| export const DID_KEY_PREFIX = 'did:key:'; | ||
| export const P256_JWT_ALG = 'ES256'; | ||
| export const SECP256K1_JWT_ALG = 'ES256K'; | ||
| //# sourceMappingURL=const.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"const.js","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AAC9C,QAAA,oBAAoB,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AACnD,QAAA,uBAAuB,GAAG,GAAG,CAAA;AAC7B,QAAA,cAAc,GAAG,UAAU,CAAA;AAE3B,QAAA,YAAY,GAAG,OAAO,CAAA;AACtB,QAAA,iBAAiB,GAAG,QAAQ,CAAA","sourcesContent":["export const P256_DID_PREFIX = new Uint8Array([0x80, 0x24])\nexport const SECP256K1_DID_PREFIX = new Uint8Array([0xe7, 0x01])\nexport const BASE58_MULTIBASE_PREFIX = 'z'\nexport const DID_KEY_PREFIX = 'did:key:'\n\nexport const P256_JWT_ALG = 'ES256'\nexport const SECP256K1_JWT_ALG = 'ES256K'\n"]} | ||
| {"version":3,"file":"const.js","sourceRoot":"","sources":["../src/const.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AAC3D,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AAChE,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAA;AAC1C,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAA;AAExC,MAAM,CAAC,MAAM,YAAY,GAAG,OAAO,CAAA;AACnC,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAQ,CAAA","sourcesContent":["export const P256_DID_PREFIX = new Uint8Array([0x80, 0x24])\nexport const SECP256K1_DID_PREFIX = new Uint8Array([0xe7, 0x01])\nexport const BASE58_MULTIBASE_PREFIX = 'z'\nexport const DID_KEY_PREFIX = 'did:key:'\n\nexport const P256_JWT_ALG = 'ES256'\nexport const SECP256K1_JWT_ALG = 'ES256K'\n"]} |
+15
-55
@@ -1,45 +0,8 @@ | ||
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || (function () { | ||
| var ownKeys = function(o) { | ||
| ownKeys = Object.getOwnPropertyNames || function (o) { | ||
| var ar = []; | ||
| for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
| return ar; | ||
| }; | ||
| return ownKeys(o); | ||
| }; | ||
| return function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| })(); | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.parseDidKey = exports.formatMultikey = exports.parseMultikey = void 0; | ||
| exports.formatDidKey = formatDidKey; | ||
| const uint8arrays = __importStar(require("uint8arrays")); | ||
| const const_1 = require("./const"); | ||
| const plugins_1 = require("./plugins"); | ||
| const utils_1 = require("./utils"); | ||
| const parseMultikey = (multikey) => { | ||
| const prefixedBytes = (0, utils_1.extractPrefixedBytes)(multikey); | ||
| const plugin = plugins_1.plugins.find((p) => (0, utils_1.hasPrefix)(prefixedBytes, p.prefix)); | ||
| import * as uint8arrays from 'uint8arrays'; | ||
| import { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const.js'; | ||
| import { plugins } from './plugins.js'; | ||
| import { extractMultikey, extractPrefixedBytes, hasPrefix } from './utils.js'; | ||
| export const parseMultikey = (multikey) => { | ||
| const prefixedBytes = extractPrefixedBytes(multikey); | ||
| const plugin = plugins.find((p) => hasPrefix(prefixedBytes, p.prefix)); | ||
| if (!plugin) { | ||
@@ -54,5 +17,4 @@ throw new Error('Unsupported key type'); | ||
| }; | ||
| exports.parseMultikey = parseMultikey; | ||
| const formatMultikey = (jwtAlg, keyBytes) => { | ||
| const plugin = plugins_1.plugins.find((p) => p.jwtAlg === jwtAlg); | ||
| export const formatMultikey = (jwtAlg, keyBytes) => { | ||
| const plugin = plugins.find((p) => p.jwtAlg === jwtAlg); | ||
| if (!plugin) { | ||
@@ -65,13 +27,11 @@ throw new Error('Unsupported key type'); | ||
| ]); | ||
| return (const_1.BASE58_MULTIBASE_PREFIX + uint8arrays.toString(prefixedBytes, 'base58btc')); | ||
| return (BASE58_MULTIBASE_PREFIX + uint8arrays.toString(prefixedBytes, 'base58btc')); | ||
| }; | ||
| exports.formatMultikey = formatMultikey; | ||
| const parseDidKey = (did) => { | ||
| const multikey = (0, utils_1.extractMultikey)(did); | ||
| return (0, exports.parseMultikey)(multikey); | ||
| export const parseDidKey = (did) => { | ||
| const multikey = extractMultikey(did); | ||
| return parseMultikey(multikey); | ||
| }; | ||
| exports.parseDidKey = parseDidKey; | ||
| function formatDidKey(jwtAlg, keyBytes) { | ||
| return `${const_1.DID_KEY_PREFIX}${(0, exports.formatMultikey)(jwtAlg, keyBytes)}`; | ||
| export function formatDidKey(jwtAlg, keyBytes) { | ||
| return `${DID_KEY_PREFIX}${formatMultikey(jwtAlg, keyBytes)}`; | ||
| } | ||
| //# sourceMappingURL=did.js.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"did.js","sourceRoot":"","sources":["../src/did.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,oCAKC;AApDD,yDAA0C;AAC1C,mCAAiE;AACjE,uCAAmC;AACnC,mCAA0E;AAOnE,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAkB,EAAE;IAChE,MAAM,aAAa,GAAG,IAAA,4BAAoB,EAAC,QAAQ,CAAC,CAAA;IACpD,MAAM,MAAM,GAAG,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,iBAAS,EAAC,aAAa,EAAE,CAAC,CA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AC,EAAW,CAAA;AACxE,CAAC","sourcesContent":["import * as uint8arrays from 'uint8arrays'\nimport { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const'\nimport { plugins } from './plugins'\nimport { extractMultikey, extractPrefixedBytes, hasPrefix } from './utils'\n\nexport type ParsedMultikey = {\n jwtAlg: string\n keyBytes: Uint8Array\n}\n\nexport const parseMultikey = (multikey: string): ParsedMultikey => {\n const prefixedBytes = extractPrefixedBytes(multikey)\n const plugin = plugins.find((p) => hasPrefix(prefixedBytes, p.prefix))\n if (!plugin) {\n throw new Error('Unsupported key type')\n }\n const keyBytes = plugin.decompressPubkey(\n prefixedBytes.slice(plugin.prefix.length),\n )\n return {\n jwtAlg: plugin.jwtAlg,\n keyBytes,\n }\n}\n\nexport const formatMultikey = (\n jwtAlg: string,\n keyBytes: Uint8Array,\n): string => {\n const plugin = plugins.find((p) => p.jwtAlg === jwtAlg)\n if (!plugin) {\n throw new Error('Unsupported key type')\n }\n const prefixedBytes = uint8arrays.concat([\n plugin.prefix,\n plugin.compressPubkey(keyBytes),\n ])\n return (\n BASE58_MULTIBASE_PREFIX + uint8arrays.toString(prefixedBytes, 'base58btc')\n )\n}\n\nexport const parseDidKey = (did: string): ParsedMultikey => {\n const multikey = extractMultikey(did)\n return parseMultikey(multikey)\n}\n\nexport function formatDidKey(\n jwtAlg: string,\n keyBytes: Uint8Array,\n): `did:key:${string}` {\n return `${DID_KEY_PREFIX}${formatMultikey(jwtAlg, keyBytes)}` as const\n}\n"]} | ||
| {"version":3,"file":"did.js","sourceRoot":"","sources":["../src/did.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAO7E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,QAAQ,CAAC,CAAA;AAChC,CAAC,CAAA;AAED,MAAM,UAAU,YAAY,CAC1B,MAAc,EACd,QAAoB;IAEpB,OAAO,GAAG,cAAc,GAAG,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAW,CAAA;AACxE,CAAC","sourcesContent":["import * as uint8arrays from 'uint8arrays'\nimport { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const.js'\nimport { plugins } from './plugins.js'\nimport { extractMultikey, extractPrefixedBytes, hasPrefix } from './utils.js'\n\nexport type ParsedMultikey = {\n jwtAlg: string\n keyBytes: Uint8Array\n}\n\nexport const parseMultikey = (multikey: string): ParsedMultikey => {\n const prefixedBytes = extractPrefixedBytes(multikey)\n const plugin = plugins.find((p) => hasPrefix(prefixedBytes, p.prefix))\n if (!plugin) {\n throw new Error('Unsupported key type')\n }\n const keyBytes = plugin.decompressPubkey(\n prefixedBytes.slice(plugin.prefix.length),\n )\n return {\n jwtAlg: plugin.jwtAlg,\n keyBytes,\n }\n}\n\nexport const formatMultikey = (\n jwtAlg: string,\n keyBytes: Uint8Array,\n): string => {\n const plugin = plugins.find((p) => p.jwtAlg === jwtAlg)\n if (!plugin) {\n throw new Error('Unsupported key type')\n }\n const prefixedBytes = uint8arrays.concat([\n plugin.prefix,\n plugin.compressPubkey(keyBytes),\n ])\n return (\n BASE58_MULTIBASE_PREFIX + uint8arrays.toString(prefixedBytes, 'base58btc')\n )\n}\n\nexport const parseDidKey = (did: string): ParsedMultikey => {\n const multikey = extractMultikey(did)\n return parseMultikey(multikey)\n}\n\nexport function formatDidKey(\n jwtAlg: string,\n keyBytes: Uint8Array,\n): `did:key:${string}` {\n return `${DID_KEY_PREFIX}${formatMultikey(jwtAlg, keyBytes)}` as const\n}\n"]} |
+12
-12
@@ -1,13 +0,13 @@ | ||
| export * from './const'; | ||
| export * from './did'; | ||
| export * from './multibase'; | ||
| export * from './random'; | ||
| export * from './sha'; | ||
| export * from './types'; | ||
| export * from './verify'; | ||
| export * from './utils'; | ||
| export * from './p256/keypair'; | ||
| export * from './p256/plugin'; | ||
| export * from './secp256k1/keypair'; | ||
| export * from './secp256k1/plugin'; | ||
| export * from './const.js'; | ||
| export * from './did.js'; | ||
| export * from './multibase.js'; | ||
| export * from './random.js'; | ||
| export * from './sha.js'; | ||
| export * from './types.js'; | ||
| export * from './verify.js'; | ||
| export * from './utils.js'; | ||
| export * from './p256/keypair.js'; | ||
| export * from './p256/plugin.js'; | ||
| export * from './secp256k1/keypair.js'; | ||
| export * from './secp256k1/plugin.js'; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA;AACrB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA;AACrB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AAEvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAE7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAE1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAEhC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA"} |
+12
-28
@@ -1,29 +0,13 @@ | ||
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| __exportStar(require("./const"), exports); | ||
| __exportStar(require("./did"), exports); | ||
| __exportStar(require("./multibase"), exports); | ||
| __exportStar(require("./random"), exports); | ||
| __exportStar(require("./sha"), exports); | ||
| __exportStar(require("./types"), exports); | ||
| __exportStar(require("./verify"), exports); | ||
| __exportStar(require("./utils"), exports); | ||
| __exportStar(require("./p256/keypair"), exports); | ||
| __exportStar(require("./p256/plugin"), exports); | ||
| __exportStar(require("./secp256k1/keypair"), exports); | ||
| __exportStar(require("./secp256k1/plugin"), exports); | ||
| export * from './const.js'; | ||
| export * from './did.js'; | ||
| export * from './multibase.js'; | ||
| export * from './random.js'; | ||
| export * from './sha.js'; | ||
| export * from './types.js'; | ||
| export * from './verify.js'; | ||
| export * from './utils.js'; | ||
| export * from './p256/keypair.js'; | ||
| export * from './p256/plugin.js'; | ||
| export * from './secp256k1/keypair.js'; | ||
| export * from './secp256k1/plugin.js'; | ||
| //# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,wCAAqB;AACrB,8CAA2B;AAC3B,2CAAwB;AACxB,wCAAqB;AACrB,0CAAuB;AACvB,2CAAwB;AACxB,0CAAuB;AAEvB,iDAA8B;AAC9B,gDAA6B;AAE7B,sDAAmC;AACnC,qDAAkC","sourcesContent":["export * from './const'\nexport * from './did'\nexport * from './multibase'\nexport * from './random'\nexport * from './sha'\nexport * from './types'\nexport * from './verify'\nexport * from './utils'\n\nexport * from './p256/keypair'\nexport * from './p256/plugin'\n\nexport * from './secp256k1/keypair'\nexport * from './secp256k1/plugin'\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAE1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAEhC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA","sourcesContent":["export * from './const.js'\nexport * from './did.js'\nexport * from './multibase.js'\nexport * from './random.js'\nexport * from './sha.js'\nexport * from './types.js'\nexport * from './verify.js'\nexport * from './utils.js'\n\nexport * from './p256/keypair.js'\nexport * from './p256/plugin.js'\n\nexport * from './secp256k1/keypair.js'\nexport * from './secp256k1/plugin.js'\n"]} |
+3
-41
@@ -1,39 +0,3 @@ | ||
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || (function () { | ||
| var ownKeys = function(o) { | ||
| ownKeys = Object.getOwnPropertyNames || function (o) { | ||
| var ar = []; | ||
| for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
| return ar; | ||
| }; | ||
| return ownKeys(o); | ||
| }; | ||
| return function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| })(); | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.bytesToMultibase = exports.multibaseToBytes = void 0; | ||
| const uint8arrays = __importStar(require("uint8arrays")); | ||
| const multibaseToBytes = (mb) => { | ||
| import * as uint8arrays from 'uint8arrays'; | ||
| export const multibaseToBytes = (mb) => { | ||
| const base = mb[0]; | ||
@@ -62,4 +26,3 @@ const key = mb.slice(1); | ||
| }; | ||
| exports.multibaseToBytes = multibaseToBytes; | ||
| const bytesToMultibase = (mb, encoding) => { | ||
| export const bytesToMultibase = (mb, encoding) => { | ||
| switch (encoding) { | ||
@@ -86,3 +49,2 @@ case 'base16': | ||
| }; | ||
| exports.bytesToMultibase = bytesToMultibase; | ||
| //# sourceMappingURL=multibase.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"multibase.js","sourceRoot":"","sources":["../src/multibase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA0C;AAGnC,MAAM,gBAAgB,GAAG,CAAC,EAAU,EAAc,EAAE;IACzD,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;IAClB,MAAM,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC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;QACjD,KAAK,aAAa;YAChB,OAAO,GAAG,GAAG,WAAW,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;QACjD,KAAK,WAAW;YACd,OAAO,GAAG,GAAG,WAAW,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;QACjD,KAAK,QAAQ;YACX,OAAO,GAAG,GAAG,WAAW,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;QACjD,KAAK,WAAW;YACd,OAAO,GAAG,GAAG,WAAW,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;QACjD,KAAK,cAAc;YACjB,OAAO,GAAG,GAAG,WAAW,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;QACjD;YACE,MAAM,IAAI,KAAK,CAAC,2BAA2B,QAAQ,EAAE,CAAC,CAAA;IAC1D,CAAC;AACH,CAAC,CAAA;AAxBY,QAAA,gBAAgB,oBAwB5B","sourcesContent":["import * as uint8arrays from 'uint8arrays'\nimport { SupportedEncodings } from 'uint8arrays/to-string'\n\nexport const multibaseToBytes = (mb: string): Uint8Array => {\n const base = mb[0]\n const key = mb.slice(1)\n switch (base) {\n case 'f':\n return uint8arrays.fromString(key, 'base16')\n case 'F':\n return uint8arrays.fromString(key, 'base16upper')\n case 'b':\n return uint8arrays.fromString(key, 'base32')\n case 'B':\n return uint8arrays.fromString(key, 'base32upper')\n case 'z':\n return uint8arrays.fromString(key, 'base58btc')\n case 'm':\n return uint8arrays.fromString(key, 'base64')\n case 'u':\n return uint8arrays.fromString(key, 'base64url')\n case 'U':\n return uint8arrays.fromString(key, 'base64urlpad')\n default:\n throw new Error(`Unsupported multibase: :${mb}`)\n }\n}\n\nexport const bytesToMultibase = (\n mb: Uint8Array,\n encoding: SupportedEncodings,\n): string => {\n switch (encoding) {\n case 'base16':\n return 'f' + uint8arrays.toString(mb, encoding)\n case 'base16upper':\n return 'F' + uint8arrays.toString(mb, encoding)\n case 'base32':\n return 'b' + uint8arrays.toString(mb, encoding)\n case 'base32upper':\n return 'B' + uint8arrays.toString(mb, encoding)\n case 'base58btc':\n return 'z' + uint8arrays.toString(mb, encoding)\n case 'base64':\n return 'm' + uint8arrays.toString(mb, encoding)\n case 'base64url':\n return 'u' + uint8arrays.toString(mb, encoding)\n case 'base64urlpad':\n return 'U' + uint8arrays.toString(mb, encoding)\n default:\n throw new Error(`Unsupported multibase: :${encoding}`)\n }\n}\n"]} | ||
| {"version":3,"file":"multibase.js","sourceRoot":"","sources":["../src/multibase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,aAAa,CAAA;AAG1C,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAAU,EAAc,EAAE;IACzD,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;IAClB,MAAM,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACvB,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,GAAG;YACN,OAAO,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;QAC9C,KAAK,GAAG;YACN,OAAO,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;QACnD,KAAK,GAAG;YACN,OAAO,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;QAC9C,KAAK,GAAG;YACN,OAAO,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;QACnD,KAAK,GAAG;YACN,OAAO,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;QACjD,KAAK,GAAG;YACN,OAAO,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;QAC9C,KAAK,GAAG;YACN,OAAO,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;QACjD,KAAK,G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multibaseToBytes = (mb: string): Uint8Array => {\n const base = mb[0]\n const key = mb.slice(1)\n switch (base) {\n case 'f':\n return uint8arrays.fromString(key, 'base16')\n case 'F':\n return uint8arrays.fromString(key, 'base16upper')\n case 'b':\n return uint8arrays.fromString(key, 'base32')\n case 'B':\n return uint8arrays.fromString(key, 'base32upper')\n case 'z':\n return uint8arrays.fromString(key, 'base58btc')\n case 'm':\n return uint8arrays.fromString(key, 'base64')\n case 'u':\n return uint8arrays.fromString(key, 'base64url')\n case 'U':\n return uint8arrays.fromString(key, 'base64urlpad')\n default:\n throw new Error(`Unsupported multibase: :${mb}`)\n }\n}\n\nexport const bytesToMultibase = (\n mb: Uint8Array,\n encoding: SupportedEncodings,\n): string => {\n switch (encoding) {\n case 'base16':\n return 'f' + uint8arrays.toString(mb, encoding)\n case 'base16upper':\n return 'F' + uint8arrays.toString(mb, encoding)\n case 'base32':\n return 'b' + uint8arrays.toString(mb, encoding)\n case 'base32upper':\n return 'B' + uint8arrays.toString(mb, encoding)\n case 'base58btc':\n return 'z' + uint8arrays.toString(mb, encoding)\n case 'base64':\n return 'm' + uint8arrays.toString(mb, encoding)\n case 'base64url':\n return 'u' + uint8arrays.toString(mb, encoding)\n case 'base64urlpad':\n return 'U' + uint8arrays.toString(mb, encoding)\n default:\n throw new Error(`Unsupported multibase: :${encoding}`)\n }\n}\n"]} |
@@ -1,18 +0,13 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.decompressPubkey = exports.compressPubkey = void 0; | ||
| const p256_1 = require("@noble/curves/p256"); | ||
| const compressPubkey = (pubkeyBytes) => { | ||
| const point = p256_1.p256.ProjectivePoint.fromHex(pubkeyBytes); | ||
| import { p256 } from '@noble/curves/p256'; | ||
| export const compressPubkey = (pubkeyBytes) => { | ||
| const point = p256.ProjectivePoint.fromHex(pubkeyBytes); | ||
| return point.toRawBytes(true); | ||
| }; | ||
| exports.compressPubkey = compressPubkey; | ||
| const decompressPubkey = (compressed) => { | ||
| export const decompressPubkey = (compressed) => { | ||
| if (compressed.length !== 33) { | ||
| throw new Error('Expected 33 byte compress pubkey'); | ||
| } | ||
| const point = p256_1.p256.ProjectivePoint.fromHex(compressed); | ||
| const point = p256.ProjectivePoint.fromHex(compressed); | ||
| return point.toRawBytes(false); | ||
| }; | ||
| exports.decompressPubkey = decompressPubkey; | ||
| //# sourceMappingURL=encoding.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/p256/encoding.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AAElC,MAAM,cAAc,GAAG,CAAC,WAAuB,EAAc,EAAE;IACpE,MAAM,KAAK,GAAG,WAAI,CAAC,eAAe,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IACvD,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC,CAAA;AAHY,QAAA,cAAc,kBAG1B;AAEM,MAAM,gBAAgB,GAAG,CAAC,UAAsB,EAAc,EAAE;IACrE,IAAI,UAAU,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;IACrD,CAAC;IACD,MAAM,KAAK,GAAG,WAAI,CAAC,eAAe,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IACtD,OAAO,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC,CAAA;AANY,QAAA,gBAAgB,oBAM5B","sourcesContent":["import { p256 } from '@noble/curves/p256'\n\nexport const compressPubkey = (pubkeyBytes: Uint8Array): Uint8Array => {\n const point = p256.ProjectivePoint.fromHex(pubkeyBytes)\n return point.toRawBytes(true)\n}\n\nexport const decompressPubkey = (compressed: Uint8Array): Uint8Array => {\n if (compressed.length !== 33) {\n throw new Error('Expected 33 byte compress pubkey')\n }\n const point = p256.ProjectivePoint.fromHex(compressed)\n return point.toRawBytes(false)\n}\n"]} | ||
| {"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/p256/encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AAEzC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,WAAuB,EAAc,EAAE;IACpE,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IACvD,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,UAAsB,EAAc,EAAE;IACrE,IAAI,UAAU,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;IACrD,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IACtD,OAAO,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC,CAAA","sourcesContent":["import { p256 } from '@noble/curves/p256'\n\nexport const compressPubkey = (pubkeyBytes: Uint8Array): Uint8Array => {\n const point = p256.ProjectivePoint.fromHex(pubkeyBytes)\n return point.toRawBytes(true)\n}\n\nexport const decompressPubkey = (compressed: Uint8Array): Uint8Array => {\n if (compressed.length !== 33) {\n throw new Error('Expected 33 byte compress pubkey')\n }\n const point = p256.ProjectivePoint.fromHex(compressed)\n return point.toRawBytes(false)\n}\n"]} |
| import { SupportedEncodings } from 'uint8arrays/to-string'; | ||
| import { Keypair } from '../types'; | ||
| import { Keypair } from '../types.js'; | ||
| export type P256KeypairOptions = { | ||
@@ -4,0 +4,0 @@ exportable: boolean; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"keypair.d.ts","sourceRoot":"","sources":["../../src/p256/keypair.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AA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kB,CAAC,GACjC,OAAO,CAAC,WAAW,CAAC;WAMV,MAAM,CACjB,OAAO,EAAE,UAAU,GAAG,MAAM,EAC5B,IAAI,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GACjC,OAAO,CAAC,WAAW,CAAC;IAOvB,cAAc,IAAI,UAAU;IAI5B,YAAY,CAAC,QAAQ,GAAE,kBAAgC,GAAG,MAAM;IAIhE,GAAG,IAAI,MAAM;IAIP,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAO1C,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC;CAMpC"} |
+15
-73
@@ -1,73 +0,16 @@ | ||
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || (function () { | ||
| var ownKeys = function(o) { | ||
| ownKeys = Object.getOwnPropertyNames || function (o) { | ||
| var ar = []; | ||
| for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
| return ar; | ||
| }; | ||
| return ownKeys(o); | ||
| }; | ||
| return function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| })(); | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.P256Keypair = void 0; | ||
| const p256_1 = require("@noble/curves/p256"); | ||
| const sha256_1 = require("@noble/hashes/sha256"); | ||
| const uint8arrays_1 = require("uint8arrays"); | ||
| const const_1 = require("../const"); | ||
| const did = __importStar(require("../did")); | ||
| class P256Keypair { | ||
| import { p256 } from '@noble/curves/p256'; | ||
| import { sha256 } from '@noble/hashes/sha256'; | ||
| import { fromString as ui8FromString, toString as ui8ToString, } from 'uint8arrays'; | ||
| import { P256_JWT_ALG } from '../const.js'; | ||
| import * as did from '../did.js'; | ||
| export class P256Keypair { | ||
| constructor(privateKey, exportable) { | ||
| Object.defineProperty(this, "privateKey", { | ||
| enumerable: true, | ||
| configurable: true, | ||
| writable: true, | ||
| value: privateKey | ||
| }); | ||
| Object.defineProperty(this, "exportable", { | ||
| enumerable: true, | ||
| configurable: true, | ||
| writable: true, | ||
| value: exportable | ||
| }); | ||
| Object.defineProperty(this, "jwtAlg", { | ||
| enumerable: true, | ||
| configurable: true, | ||
| writable: true, | ||
| value: const_1.P256_JWT_ALG | ||
| }); | ||
| Object.defineProperty(this, "publicKey", { | ||
| enumerable: true, | ||
| configurable: true, | ||
| writable: true, | ||
| value: void 0 | ||
| }); | ||
| this.publicKey = p256_1.p256.getPublicKey(privateKey); | ||
| this.privateKey = privateKey; | ||
| this.exportable = exportable; | ||
| this.jwtAlg = P256_JWT_ALG; | ||
| this.publicKey = p256.getPublicKey(privateKey); | ||
| } | ||
| static async create(opts) { | ||
| const { exportable = false } = opts || {}; | ||
| const privKey = p256_1.p256.utils.randomPrivateKey(); | ||
| const privKey = p256.utils.randomPrivateKey(); | ||
| return new P256Keypair(privKey, exportable); | ||
@@ -77,3 +20,3 @@ } | ||
| const { exportable = false } = opts || {}; | ||
| const privKeyBytes = typeof privKey === 'string' ? (0, uint8arrays_1.fromString)(privKey, 'hex') : privKey; | ||
| const privKeyBytes = typeof privKey === 'string' ? ui8FromString(privKey, 'hex') : privKey; | ||
| return new P256Keypair(privKeyBytes, exportable); | ||
@@ -85,3 +28,3 @@ } | ||
| publicKeyStr(encoding = 'base64pad') { | ||
| return (0, uint8arrays_1.toString)(this.publicKey, encoding); | ||
| return ui8ToString(this.publicKey, encoding); | ||
| } | ||
@@ -92,5 +35,5 @@ did() { | ||
| async sign(msg) { | ||
| const msgHash = await (0, sha256_1.sha256)(msg); | ||
| const msgHash = await sha256(msg); | ||
| // return raw 64 byte sig not DER-encoded | ||
| const sig = await p256_1.p256.sign(msgHash, this.privateKey, { lowS: true }); | ||
| const sig = await p256.sign(msgHash, this.privateKey, { lowS: true }); | ||
| return sig.toCompactRawBytes(); | ||
@@ -105,3 +48,2 @@ } | ||
| } | ||
| exports.P256Keypair = P256Keypair; | ||
| //# sourceMappingURL=keypair.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"keypair.js","sourceRoot":"","sources":["../../src/p256/keypair.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAyC;AACzC,iDAA6C;AAC7C,6CAGoB;AAEpB,oCAAuC;AACvC,4CAA6B;AAO7B,MAAa,WAAW;IAItB,YACU,UAAsB,EACtB,UAAmB;QAD3B;;;;mBAAQ,UAAU;WAAY;QAC9B;;;;mBAAQ,UAAU;WAAS;QAL7B;;;;mBAAS,oBAAY;WAAA;QACb;;;;;WAAqB;QAM3B,IAAI,CAAC,SAAS,GAAG,WAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;IAChD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,IAAkC;QAElC,MAAM,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,IAAI,IAAI,EAAE,CAAA;QACzC,MAAM,OAAO,GAAG,WAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAA;QAC7C,OAAO,IAAI,WAAW,CAAC,OAAO,EAAE,UA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import {\n fromString as ui8FromString,\n toString as ui8ToString,\n} from 'uint8arrays'\nimport { SupportedEncodings } from 'uint8arrays/to-string'\nimport { P256_JWT_ALG } from '../const'\nimport * as did from '../did'\nimport { Keypair } from '../types'\n\nexport type P256KeypairOptions = {\n exportable: boolean\n}\n\nexport class P256Keypair implements Keypair {\n jwtAlg = P256_JWT_ALG\n private publicKey: Uint8Array\n\n constructor(\n private privateKey: Uint8Array,\n private exportable: boolean,\n ) {\n this.publicKey = p256.getPublicKey(privateKey)\n }\n\n static async create(\n opts?: Partial<P256KeypairOptions>,\n ): Promise<P256Keypair> {\n const { exportable = false } = opts || {}\n const privKey = p256.utils.randomPrivateKey()\n return new P256Keypair(privKey, exportable)\n }\n\n static async import(\n privKey: Uint8Array | string,\n opts?: Partial<P256KeypairOptions>,\n ): Promise<P256Keypair> {\n const { exportable = false } = opts || {}\n const privKeyBytes =\n typeof privKey === 'string' ? ui8FromString(privKey, 'hex') : privKey\n return new P256Keypair(privKeyBytes, exportable)\n }\n\n publicKeyBytes(): Uint8Array {\n return this.publicKey\n }\n\n publicKeyStr(encoding: SupportedEncodings = 'base64pad'): string {\n return ui8ToString(this.publicKey, encoding)\n }\n\n did(): string {\n return did.formatDidKey(this.jwtAlg, this.publicKey)\n }\n\n async sign(msg: Uint8Array): Promise<Uint8Array> {\n const msgHash = await sha256(msg)\n // return raw 64 byte sig not DER-encoded\n const sig = await p256.sign(msgHash, this.privateKey, { lowS: true })\n return sig.toCompactRawBytes()\n }\n\n async export(): Promise<Uint8Array> {\n if (!this.exportable) {\n throw new Error('Private key is not exportable')\n }\n return this.privateKey\n }\n}\n"]} | ||
| {"version":3,"file":"keypair.js","sourceRoot":"","sources":["../../src/p256/keypair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EACL,UAAU,IAAI,aAAa,EAC3B,QAAQ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CAAA;IACtD,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAe;QACxB,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,CAAA;QACjC,yCAAyC;QACzC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;QACrE,OAAO,GAAG,CAAC,iBAAiB,EAAE,CAAA;IAChC,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;QAClD,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;CACF","sourcesContent":["import { p256 } from '@noble/curves/p256'\nimport { sha256 } from '@noble/hashes/sha256'\nimport {\n fromString as ui8FromString,\n toString as ui8ToString,\n} from 'uint8arrays'\nimport { SupportedEncodings } from 'uint8arrays/to-string'\nimport { P256_JWT_ALG } from '../const.js'\nimport * as did from '../did.js'\nimport { Keypair } from '../types.js'\n\nexport type P256KeypairOptions = {\n exportable: boolean\n}\n\nexport class P256Keypair implements Keypair {\n jwtAlg = P256_JWT_ALG\n private publicKey: Uint8Array\n\n constructor(\n private privateKey: Uint8Array,\n private exportable: boolean,\n ) {\n this.publicKey = p256.getPublicKey(privateKey)\n }\n\n static async create(\n opts?: Partial<P256KeypairOptions>,\n ): Promise<P256Keypair> {\n const { exportable = false } = opts || {}\n const privKey = p256.utils.randomPrivateKey()\n return new P256Keypair(privKey, exportable)\n }\n\n static async import(\n privKey: Uint8Array | string,\n opts?: Partial<P256KeypairOptions>,\n ): Promise<P256Keypair> {\n const { exportable = false } = opts || {}\n const privKeyBytes =\n typeof privKey === 'string' ? ui8FromString(privKey, 'hex') : privKey\n return new P256Keypair(privKeyBytes, exportable)\n }\n\n publicKeyBytes(): Uint8Array {\n return this.publicKey\n }\n\n publicKeyStr(encoding: SupportedEncodings = 'base64pad'): string {\n return ui8ToString(this.publicKey, encoding)\n }\n\n did(): string {\n return did.formatDidKey(this.jwtAlg, this.publicKey)\n }\n\n async sign(msg: Uint8Array): Promise<Uint8Array> {\n const msgHash = await sha256(msg)\n // return raw 64 byte sig not DER-encoded\n const sig = await p256.sign(msgHash, this.privateKey, { lowS: true })\n return sig.toCompactRawBytes()\n }\n\n async export(): Promise<Uint8Array> {\n if (!this.exportable) {\n throw new Error('Private key is not exportable')\n }\n return this.privateKey\n }\n}\n"]} |
@@ -1,2 +0,2 @@ | ||
| import { VerifyOptions } from '../types'; | ||
| import { VerifyOptions } from '../types.js'; | ||
| export declare const verifyDidSig: (did: string, data: Uint8Array, sig: Uint8Array, opts?: VerifyOptions) => Promise<boolean>; | ||
@@ -3,0 +3,0 @@ export declare const verifySig: (publicKey: Uint8Array, data: Uint8Array, sig: Uint8Array, opts?: VerifyOptions) => Promise<boolean>; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/p256/operations.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAGxC,eAAO,MAAM,YAAY,GACvB,KAAK,MAAM,EACX,MAAM,UAAU,EAChB,KAAK,UAAU,EACf,OAAO,aAAa,KACnB,OAAO,CAAC,OAAO,CAOjB,CAAA;AAED,eAAO,MAAM,SAAS,GACpB,WAAW,UAAU,EACrB,MAAM,UAAU,EAChB,KAAK,UAAU,EACf,OAAO,aAAa,KACnB,OAAO,CAAC,OAAO,CAOjB,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,KAAK,UAAU,YAO9C,CAAA"} | ||
| {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/p256/operations.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAG3C,eAAO,MAAM,YAAY,GACvB,KAAK,MAAM,EACX,MAAM,UAAU,EAChB,KAAK,UAAU,EACf,OAAO,aAAa,KACnB,OAAO,CAAC,OAAO,CAOjB,CAAA;AAED,eAAO,MAAM,SAAS,GACpB,WAAW,UAAU,EACrB,MAAM,UAAU,EAChB,KAAK,UAAU,EACf,OAAO,aAAa,KACnB,OAAO,CAAC,OAAO,CAOjB,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,KAAK,UAAU,YAO9C,CAAA"} |
+16
-22
@@ -1,22 +0,18 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.isCompactFormat = exports.verifySig = exports.verifyDidSig = void 0; | ||
| const p256_1 = require("@noble/curves/p256"); | ||
| const sha256_1 = require("@noble/hashes/sha256"); | ||
| const uint8arrays_1 = require("uint8arrays"); | ||
| const const_1 = require("../const"); | ||
| const utils_1 = require("../utils"); | ||
| const verifyDidSig = async (did, data, sig, opts) => { | ||
| const prefixedBytes = (0, utils_1.extractPrefixedBytes)((0, utils_1.extractMultikey)(did)); | ||
| if (!(0, utils_1.hasPrefix)(prefixedBytes, const_1.P256_DID_PREFIX)) { | ||
| import { p256 } from '@noble/curves/p256'; | ||
| import { sha256 } from '@noble/hashes/sha256'; | ||
| import { equals as ui8equals } from 'uint8arrays'; | ||
| import { P256_DID_PREFIX } from '../const.js'; | ||
| import { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils.js'; | ||
| export const verifyDidSig = async (did, data, sig, opts) => { | ||
| const prefixedBytes = extractPrefixedBytes(extractMultikey(did)); | ||
| if (!hasPrefix(prefixedBytes, P256_DID_PREFIX)) { | ||
| throw new Error(`Not a P-256 did:key: ${did}`); | ||
| } | ||
| const keyBytes = prefixedBytes.slice(const_1.P256_DID_PREFIX.length); | ||
| return (0, exports.verifySig)(keyBytes, data, sig, opts); | ||
| const keyBytes = prefixedBytes.slice(P256_DID_PREFIX.length); | ||
| return verifySig(keyBytes, data, sig, opts); | ||
| }; | ||
| exports.verifyDidSig = verifyDidSig; | ||
| const verifySig = async (publicKey, data, sig, opts) => { | ||
| export const verifySig = async (publicKey, data, sig, opts) => { | ||
| const allowMalleable = opts?.allowMalleableSig ?? false; | ||
| const msgHash = await (0, sha256_1.sha256)(data); | ||
| return p256_1.p256.verify(sig, msgHash, publicKey, { | ||
| const msgHash = await sha256(data); | ||
| return p256.verify(sig, msgHash, publicKey, { | ||
| format: allowMalleable ? undefined : 'compact', // prevent DER-encoded signatures | ||
@@ -26,7 +22,6 @@ lowS: !allowMalleable, | ||
| }; | ||
| exports.verifySig = verifySig; | ||
| const isCompactFormat = (sig) => { | ||
| export const isCompactFormat = (sig) => { | ||
| try { | ||
| const parsed = p256_1.p256.Signature.fromCompact(sig); | ||
| return (0, uint8arrays_1.equals)(parsed.toCompactRawBytes(), sig); | ||
| const parsed = p256.Signature.fromCompact(sig); | ||
| return ui8equals(parsed.toCompactRawBytes(), sig); | ||
| } | ||
@@ -37,3 +32,2 @@ catch { | ||
| }; | ||
| exports.isCompactFormat = isCompactFormat; | ||
| //# sourceMappingURL=operations.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/p256/operations.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AACzC,iDAA6C;AAC7C,6CAAiD;AACjD,oCAA0C;AAE1C,oCAA2E;AAEpE,MAAM,YAAY,GAAG,KAAK,EAC/B,GAAW,EACX,IAAgB,EAChB,GAAe,EACf,IAAoB,EACF,EAAE;IACpB,MAAM,aAAa,GAAG,IAAA,4BAAoB,EAAC,IAAA,uBAAe,EAAC,GAAG,CAAC,CAAC,CAAA;IAChE,IAAI,CAAC,IAAA,iBAAS,EAAC,aAAa,EAAE,uBAAe,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,EAAE,CAAC,CAAA;IAChD,CAAC;IACD,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,uBAAe,CAAC,MAAM,CAAC,CAAA;IAC5D,OAAO,IAAA,iBAAS,EAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;AAC7C,CAAC,CAAA;AAZY,QAAA,YAAY,gBAYxB;AAEM,MAAM,SAAS,GAAG,KAAK,EAC5B,SAAqB,EACrB,IAAgB,EAChB,GAAe,EACf,IAAoB,EACF,EAAE;IACpB,MAAM,cAAc,GAAG,IAAI,EAAE,iBAAiB,IAAI,KAAK,CAAA;IACvD,MAAM,OAAO,GAAG,MAAM,IAAA,eAAM,EAAC,IAAI,CAAC,CAAA;IAClC,OAAO,WAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE;QAC1C,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,iCAAiC;QACjF,IAAI,EAAE,CAAC,cAAc;KACtB,CAAC,CAAA;AACJ,CAAC,CAAA;AAZY,QAAA,SAAS,aAYrB;AAEM,MAAM,eAAe,GAAG,CAAC,GAAe,EAAE,EAAE;IACjD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,WAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;QAC9C,OAAO,IAAA,oBAAS,EAAC,MAAM,CAAC,iBAAiB,EAAE,EAAE,GAAG,CAAC,CAAA;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA;AAPY,QAAA,eAAe,mBAO3B","sourcesContent":["import { p256 } from '@noble/curves/p256'\nimport { sha256 } from '@noble/hashes/sha256'\nimport { equals as ui8equals } from 'uint8arrays'\nimport { P256_DID_PREFIX } from '../const'\nimport { VerifyOptions } from '../types'\nimport { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils'\n\nexport const verifyDidSig = async (\n did: string,\n data: Uint8Array,\n sig: Uint8Array,\n opts?: VerifyOptions,\n): Promise<boolean> => {\n const prefixedBytes = extractPrefixedBytes(extractMultikey(did))\n if (!hasPrefix(prefixedBytes, P256_DID_PREFIX)) {\n throw new Error(`Not a P-256 did:key: ${did}`)\n }\n const keyBytes = prefixedBytes.slice(P256_DID_PREFIX.length)\n return verifySig(keyBytes, data, sig, opts)\n}\n\nexport const verifySig = async (\n publicKey: Uint8Array,\n data: Uint8Array,\n sig: Uint8Array,\n opts?: VerifyOptions,\n): Promise<boolean> => {\n const allowMalleable = opts?.allowMalleableSig ?? false\n const msgHash = await sha256(data)\n return p256.verify(sig, msgHash, publicKey, {\n format: allowMalleable ? undefined : 'compact', // prevent DER-encoded signatures\n lowS: !allowMalleable,\n })\n}\n\nexport const isCompactFormat = (sig: Uint8Array) => {\n try {\n const parsed = p256.Signature.fromCompact(sig)\n return ui8equals(parsed.toCompactRawBytes(), sig)\n } catch {\n return false\n }\n}\n"]} | ||
| {"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/p256/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE9E,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,GAAW,EACX,IAAgB,EAChB,GAAe,EACf,IAAoB,EACF,EAAE;IACpB,MAAM,aAAa,GAAG,oBAAoB,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAA;IAChE,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,eAAe,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,EAAE,CAAC,CAAA;IAChD,CAAC;IACD,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;IAC5D,OAAO,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;AAC7C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAC5B,SAAqB,EACrB,IAAgB,EAChB,GAAe,EACf,IAAoB,EACF,EAAE;IACpB,MAAM,cAAc,GAAG,IAAI,EAAE,iBAAiB,IAAI,KAAK,CAAA;IACvD,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAA;IAClC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE;QAC1C,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,iCAAiC;QACjF,IAAI,EAAE,CAAC,cAAc;KACtB,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAe,EAAE,EAAE;IACjD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;QAC9C,OAAO,SAAS,CAAC,MAAM,CAAC,iBAAiB,EAAE,EAAE,GAAG,CAAC,CAAA;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { p256 } from '@noble/curves/p256'\nimport { sha256 } from '@noble/hashes/sha256'\nimport { equals as ui8equals } from 'uint8arrays'\nimport { P256_DID_PREFIX } from '../const.js'\nimport { VerifyOptions } from '../types.js'\nimport { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils.js'\n\nexport const verifyDidSig = async (\n did: string,\n data: Uint8Array,\n sig: Uint8Array,\n opts?: VerifyOptions,\n): Promise<boolean> => {\n const prefixedBytes = extractPrefixedBytes(extractMultikey(did))\n if (!hasPrefix(prefixedBytes, P256_DID_PREFIX)) {\n throw new Error(`Not a P-256 did:key: ${did}`)\n }\n const keyBytes = prefixedBytes.slice(P256_DID_PREFIX.length)\n return verifySig(keyBytes, data, sig, opts)\n}\n\nexport const verifySig = async (\n publicKey: Uint8Array,\n data: Uint8Array,\n sig: Uint8Array,\n opts?: VerifyOptions,\n): Promise<boolean> => {\n const allowMalleable = opts?.allowMalleableSig ?? false\n const msgHash = await sha256(data)\n return p256.verify(sig, msgHash, publicKey, {\n format: allowMalleable ? undefined : 'compact', // prevent DER-encoded signatures\n lowS: !allowMalleable,\n })\n}\n\nexport const isCompactFormat = (sig: Uint8Array) => {\n try {\n const parsed = p256.Signature.fromCompact(sig)\n return ui8equals(parsed.toCompactRawBytes(), sig)\n } catch {\n return false\n }\n}\n"]} |
@@ -1,3 +0,3 @@ | ||
| import { DidKeyPlugin } from '../types'; | ||
| import { DidKeyPlugin } from '../types.js'; | ||
| export declare const p256Plugin: DidKeyPlugin; | ||
| //# sourceMappingURL=plugin.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/p256/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAIvC,eAAO,MAAM,UAAU,EAAE,YAOxB,CAAA"} | ||
| {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/p256/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1C,eAAO,MAAM,UAAU,EAAE,YAOxB,CAAA"} |
+9
-12
@@ -1,14 +0,11 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.p256Plugin = void 0; | ||
| const const_1 = require("../const"); | ||
| const encoding_1 = require("./encoding"); | ||
| const operations_1 = require("./operations"); | ||
| exports.p256Plugin = { | ||
| prefix: const_1.P256_DID_PREFIX, | ||
| jwtAlg: const_1.P256_JWT_ALG, | ||
| verifySignature: operations_1.verifyDidSig, | ||
| compressPubkey: encoding_1.compressPubkey, | ||
| decompressPubkey: encoding_1.decompressPubkey, | ||
| import { P256_DID_PREFIX, P256_JWT_ALG } from '../const.js'; | ||
| import { compressPubkey, decompressPubkey } from './encoding.js'; | ||
| import { verifyDidSig } from './operations.js'; | ||
| export const p256Plugin = { | ||
| prefix: P256_DID_PREFIX, | ||
| jwtAlg: P256_JWT_ALG, | ||
| verifySignature: verifyDidSig, | ||
| compressPubkey, | ||
| decompressPubkey, | ||
| }; | ||
| //# sourceMappingURL=plugin.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/p256/plugin.ts"],"names":[],"mappings":";;;AAAA,oCAAwD;AAExD,yCAA6D;AAC7D,6CAA2C;AAE9B,QAAA,UAAU,GAAiB;IACtC,MAAM,EAAE,uBAAe;IACvB,MAAM,EAAE,oBAAY;IACpB,eAAe,EAAE,yBAAY;IAE7B,cAAc,EAAd,yBAAc;IACd,gBAAgB,EAAhB,2BAAgB;CACjB,CAAA","sourcesContent":["import { P256_DID_PREFIX, P256_JWT_ALG } from '../const'\nimport { DidKeyPlugin } from '../types'\nimport { compressPubkey, decompressPubkey } from './encoding'\nimport { verifyDidSig } from './operations'\n\nexport const p256Plugin: DidKeyPlugin = {\n prefix: P256_DID_PREFIX,\n jwtAlg: P256_JWT_ALG,\n verifySignature: verifyDidSig,\n\n compressPubkey,\n decompressPubkey,\n}\n"]} | ||
| {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/p256/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE3D,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,MAAM,CAAC,MAAM,UAAU,GAAiB;IACtC,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,YAAY;IACpB,eAAe,EAAE,YAAY;IAE7B,cAAc;IACd,gBAAgB;CACjB,CAAA","sourcesContent":["import { P256_DID_PREFIX, P256_JWT_ALG } from '../const.js'\nimport { DidKeyPlugin } from '../types.js'\nimport { compressPubkey, decompressPubkey } from './encoding.js'\nimport { verifyDidSig } from './operations.js'\n\nexport const p256Plugin: DidKeyPlugin = {\n prefix: P256_DID_PREFIX,\n jwtAlg: P256_JWT_ALG,\n verifySignature: verifyDidSig,\n\n compressPubkey,\n decompressPubkey,\n}\n"]} |
@@ -1,2 +0,2 @@ | ||
| export declare const plugins: import("./types").DidKeyPlugin[]; | ||
| export declare const plugins: import("./types.js").DidKeyPlugin[]; | ||
| //# sourceMappingURL=plugins.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,kCAAgC,CAAA"} | ||
| {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,qCAAgC,CAAA"} |
+3
-6
@@ -1,7 +0,4 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.plugins = void 0; | ||
| const plugin_1 = require("./p256/plugin"); | ||
| const plugin_2 = require("./secp256k1/plugin"); | ||
| exports.plugins = [plugin_1.p256Plugin, plugin_2.secp256k1Plugin]; | ||
| import { p256Plugin } from './p256/plugin.js'; | ||
| import { secp256k1Plugin } from './secp256k1/plugin.js'; | ||
| export const plugins = [p256Plugin, secp256k1Plugin]; | ||
| //# sourceMappingURL=plugins.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,+CAAoD;AAEvC,QAAA,OAAO,GAAG,CAAC,mBAAU,EAAE,wBAAe,CAAC,CAAA","sourcesContent":["import { p256Plugin } from './p256/plugin'\nimport { secp256k1Plugin } from './secp256k1/plugin'\n\nexport const plugins = [p256Plugin, secp256k1Plugin]\n"]} | ||
| {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,UAAU,EAAE,eAAe,CAAC,CAAA","sourcesContent":["import { p256Plugin } from './p256/plugin.js'\nimport { secp256k1Plugin } from './secp256k1/plugin.js'\n\nexport const plugins = [p256Plugin, secp256k1Plugin]\n"]} |
+1
-2
@@ -1,6 +0,5 @@ | ||
| import * as noble from '@noble/hashes/utils'; | ||
| import { SupportedEncodings } from 'uint8arrays/to-string'; | ||
| export declare const randomBytes: typeof noble.randomBytes; | ||
| export declare const randomBytes: (bytesLength?: number) => Uint8Array<ArrayBuffer>; | ||
| export declare const randomStr: (byteLength: number, encoding: SupportedEncodings) => string; | ||
| export declare const randomIntFromSeed: (seed: string, high: number, low?: number) => Promise<number>; | ||
| //# sourceMappingURL=random.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,qBAAqB,CAAA;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAG1D,eAAO,MAAM,WAAW,0BAAoB,CAAA;AAE5C,eAAO,MAAM,SAAS,GACpB,YAAY,MAAM,EAClB,UAAU,kBAAkB,KAC3B,MAGF,CAAA;AAED,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,MAAM,MAAM,EACZ,YAAO,KACN,OAAO,CAAC,MAAM,CAMhB,CAAA"} | ||
| {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAG1D,eAAO,MAAM,WAAW,EAAwB,CAC9C,WAAW,CAAC,EAAE,MAAM,KACjB,UAAU,CAAC,WAAW,CAAC,CAAA;AAE5B,eAAO,MAAM,SAAS,GACpB,YAAY,MAAM,EAClB,UAAU,kBAAkB,KAC3B,MAGF,CAAA;AAED,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,MAAM,MAAM,EACZ,YAAO,KACN,OAAO,CAAC,MAAM,CAMhB,CAAA"} |
+8
-46
@@ -1,48 +0,11 @@ | ||
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || (function () { | ||
| var ownKeys = function(o) { | ||
| ownKeys = Object.getOwnPropertyNames || function (o) { | ||
| var ar = []; | ||
| for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
| return ar; | ||
| }; | ||
| return ownKeys(o); | ||
| }; | ||
| return function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| })(); | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.randomIntFromSeed = exports.randomStr = exports.randomBytes = void 0; | ||
| const noble = __importStar(require("@noble/hashes/utils")); | ||
| const uint8arrays = __importStar(require("uint8arrays")); | ||
| const sha_1 = require("./sha"); | ||
| exports.randomBytes = noble.randomBytes; | ||
| const randomStr = (byteLength, encoding) => { | ||
| const bytes = (0, exports.randomBytes)(byteLength); | ||
| import * as noble from '@noble/hashes/utils'; | ||
| import * as uint8arrays from 'uint8arrays'; | ||
| import { sha256 } from './sha.js'; | ||
| export const randomBytes = noble.randomBytes; | ||
| export const randomStr = (byteLength, encoding) => { | ||
| const bytes = randomBytes(byteLength); | ||
| return uint8arrays.toString(bytes, encoding); | ||
| }; | ||
| exports.randomStr = randomStr; | ||
| const randomIntFromSeed = async (seed, high, low = 0) => { | ||
| const hash = await (0, sha_1.sha256)(seed); | ||
| export const randomIntFromSeed = async (seed, high, low = 0) => { | ||
| const hash = await sha256(seed); | ||
| const number = Buffer.from(hash).readUintBE(0, 6); | ||
@@ -53,3 +16,2 @@ const range = high - low; | ||
| }; | ||
| exports.randomIntFromSeed = randomIntFromSeed; | ||
| //# sourceMappingURL=random.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"random.js","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAA4C;AAC5C,yDAA0C;AAE1C,+BAA8B;AAEjB,QAAA,WAAW,GAAG,KAAK,CAAC,WAAW,CAAA;AAErC,MAAM,SAAS,GAAG,CACvB,UAAkB,EAClB,QAA4B,EACpB,EAAE;IACV,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,UAAU,CAAC,CAAA;IACrC,OAAO,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;AAC9C,CAAC,CAAA;AANY,QAAA,SAAS,aAMrB;AAEM,MAAM,iBAAiB,GAAG,KAAK,EACpC,IAAY,EACZ,IAAY,EACZ,GAAG,GAAG,CAAC,EACU,EAAE;IACnB,MAAM,IAAI,GAAG,MAAM,IAAA,YAAM,EAAC,IAAI,CAAC,CAAA;IAC/B,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACjD,MAAM,KAAK,GAAG,IAAI,GAAG,GAAG,CAAA;IACxB,MAAM,UAAU,GAAG,MAAM,GAAG,KAAK,CAAA;IACjC,OAAO,UAAU,GAAG,GAAG,CAAA;AACzB,CAAC,CAAA;AAVY,QAAA,iBAAiB,qBAU7B","sourcesContent":["import * as noble from '@noble/hashes/utils'\nimport * as uint8arrays from 'uint8arrays'\nimport { SupportedEncodings } from 'uint8arrays/to-string'\nimport { sha256 } from './sha'\n\nexport const randomBytes = noble.randomBytes\n\nexport const randomStr = (\n byteLength: number,\n encoding: SupportedEncodings,\n): string => {\n const bytes = randomBytes(byteLength)\n return uint8arrays.toString(bytes, encoding)\n}\n\nexport const randomIntFromSeed = async (\n seed: string,\n high: number,\n low = 0,\n): Promise<number> => {\n const hash = await sha256(seed)\n const number = Buffer.from(hash).readUintBE(0, 6)\n const range = high - low\n const normalized = number % range\n return normalized + low\n}\n"]} | ||
| {"version":3,"file":"random.js","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,WAAW,MAAM,aAAa,CAAA;AAE1C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,WAEL,CAAA;AAE5B,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,UAAkB,EAClB,QAA4B,EACpB,EAAE;IACV,MAAM,KAAK,GAAG,WAAW,CAAC,UAAU,CAAC,CAAA;IACrC,OAAO,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;AAC9C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,IAAY,EACZ,IAAY,EACZ,GAAG,GAAG,CAAC,EACU,EAAE;IACnB,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAA;IAC/B,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACjD,MAAM,KAAK,GAAG,IAAI,GAAG,GAAG,CAAA;IACxB,MAAM,UAAU,GAAG,MAAM,GAAG,KAAK,CAAA;IACjC,OAAO,UAAU,GAAG,GAAG,CAAA;AACzB,CAAC,CAAA","sourcesContent":["import * as noble from '@noble/hashes/utils'\nimport * as uint8arrays from 'uint8arrays'\nimport { SupportedEncodings } from 'uint8arrays/to-string'\nimport { sha256 } from './sha.js'\n\nexport const randomBytes = noble.randomBytes as (\n bytesLength?: number,\n) => Uint8Array<ArrayBuffer>\n\nexport const randomStr = (\n byteLength: number,\n encoding: SupportedEncodings,\n): string => {\n const bytes = randomBytes(byteLength)\n return uint8arrays.toString(bytes, encoding)\n}\n\nexport const randomIntFromSeed = async (\n seed: string,\n high: number,\n low = 0,\n): Promise<number> => {\n const hash = await sha256(seed)\n const number = Buffer.from(hash).readUintBE(0, 6)\n const range = high - low\n const normalized = number % range\n return normalized + low\n}\n"]} |
@@ -1,18 +0,13 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.decompressPubkey = exports.compressPubkey = void 0; | ||
| const secp256k1_1 = require("@noble/curves/secp256k1"); | ||
| const compressPubkey = (pubkeyBytes) => { | ||
| const point = secp256k1_1.secp256k1.ProjectivePoint.fromHex(pubkeyBytes); | ||
| import { secp256k1 as k256 } from '@noble/curves/secp256k1'; | ||
| export const compressPubkey = (pubkeyBytes) => { | ||
| const point = k256.ProjectivePoint.fromHex(pubkeyBytes); | ||
| return point.toRawBytes(true); | ||
| }; | ||
| exports.compressPubkey = compressPubkey; | ||
| const decompressPubkey = (compressed) => { | ||
| export const decompressPubkey = (compressed) => { | ||
| if (compressed.length !== 33) { | ||
| throw new Error('Expected 33 byte compress pubkey'); | ||
| } | ||
| const point = secp256k1_1.secp256k1.ProjectivePoint.fromHex(compressed); | ||
| const point = k256.ProjectivePoint.fromHex(compressed); | ||
| return point.toRawBytes(false); | ||
| }; | ||
| exports.decompressPubkey = decompressPubkey; | ||
| //# sourceMappingURL=encoding.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/secp256k1/encoding.ts"],"names":[],"mappings":";;;AAAA,uDAA2D;AAEpD,MAAM,cAAc,GAAG,CAAC,WAAuB,EAAc,EAAE;IACpE,MAAM,KAAK,GAAG,qBAAI,CAAC,eAAe,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IACvD,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC,CAAA;AAHY,QAAA,cAAc,kBAG1B;AAEM,MAAM,gBAAgB,GAAG,CAAC,UAAsB,EAAc,EAAE;IACrE,IAAI,UAAU,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;IACrD,CAAC;IACD,MAAM,KAAK,GAAG,qBAAI,CAAC,eAAe,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IACtD,OAAO,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC,CAAA;AANY,QAAA,gBAAgB,oBAM5B","sourcesContent":["import { secp256k1 as k256 } from '@noble/curves/secp256k1'\n\nexport const compressPubkey = (pubkeyBytes: Uint8Array): Uint8Array => {\n const point = k256.ProjectivePoint.fromHex(pubkeyBytes)\n return point.toRawBytes(true)\n}\n\nexport const decompressPubkey = (compressed: Uint8Array): Uint8Array => {\n if (compressed.length !== 33) {\n throw new Error('Expected 33 byte compress pubkey')\n }\n const point = k256.ProjectivePoint.fromHex(compressed)\n return point.toRawBytes(false)\n}\n"]} | ||
| {"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/secp256k1/encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAE3D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,WAAuB,EAAc,EAAE;IACpE,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IACvD,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,UAAsB,EAAc,EAAE;IACrE,IAAI,UAAU,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;IACrD,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IACtD,OAAO,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;AAChC,CAAC,CAAA","sourcesContent":["import { secp256k1 as k256 } from '@noble/curves/secp256k1'\n\nexport const compressPubkey = (pubkeyBytes: Uint8Array): Uint8Array => {\n const point = k256.ProjectivePoint.fromHex(pubkeyBytes)\n return point.toRawBytes(true)\n}\n\nexport const decompressPubkey = (compressed: Uint8Array): Uint8Array => {\n if (compressed.length !== 33) {\n throw new Error('Expected 33 byte compress pubkey')\n }\n const point = k256.ProjectivePoint.fromHex(compressed)\n return point.toRawBytes(false)\n}\n"]} |
| import { SupportedEncodings } from 'uint8arrays/to-string'; | ||
| import { Keypair } from '../types'; | ||
| import { Keypair } from '../types.js'; | ||
| export type Secp256k1KeypairOptions = { | ||
@@ -4,0 +4,0 @@ exportable: boolean; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"keypair.d.ts","sourceRoot":"","sources":["../../src/secp256k1/keypair.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAG1D,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAElC,MAAM,MAAM,uBAAuB,GAAG;IACpC,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,qBAAa,gBAAiB,YAAW,OAAO;IAK5C,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,UAAU;IALpB,MAAM,SAAoB;IAC1B,OAAO,CAAC,SAAS,CAAY;gBAGnB,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,OAAO;WAKhB,MAAM,CACjB,IAAI,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GACtC,OAAO,CAAC,gBAAgB,CAAC;WAMf,MAAM,CACjB,OAAO,EAAE,UAAU,GAAG,MAAM,EAC5B,IAAI,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GACtC,OAAO,CAAC,gBAAgB,CAAC;IAO5B,cAAc,IAAI,UAAU;IAI5B,YAAY,CAAC,QAAQ,GAAE,kBAAgC,GAAG,MAAM;IAIhE,GAAG,IAAI,MAAM;IAIP,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAO1C,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC;CAMpC"} | ||
| {"version":3,"file":"keypair.d.ts","sourceRoot":"","sources":["../../src/secp256k1/keypair.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAG1D,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAErC,MAAM,MAAM,uBAAuB,GAAG;IACpC,UAAU,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,qBAAa,gBAAiB,YAAW,OAAO;IAK5C,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,UAAU;IALpB,MAAM,SAAoB;IAC1B,OAAO,CAAC,SAAS,CAAY;gBAGnB,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,OAAO;WAKhB,MAAM,CACjB,IAAI,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GACtC,OAAO,CAAC,gBAAgB,CAAC;WAMf,MAAM,CACjB,OAAO,EAAE,UAAU,GAAG,MAAM,EAC5B,IAAI,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GACtC,OAAO,CAAC,gBAAgB,CAAC;IAO5B,cAAc,IAAI,UAAU;IAI5B,YAAY,CAAC,QAAQ,GAAE,kBAAgC,GAAG,MAAM;IAIhE,GAAG,IAAI,MAAM;IAIP,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAO1C,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC;CAMpC"} |
@@ -1,73 +0,16 @@ | ||
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || (function () { | ||
| var ownKeys = function(o) { | ||
| ownKeys = Object.getOwnPropertyNames || function (o) { | ||
| var ar = []; | ||
| for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
| return ar; | ||
| }; | ||
| return ownKeys(o); | ||
| }; | ||
| return function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| })(); | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Secp256k1Keypair = void 0; | ||
| const secp256k1_1 = require("@noble/curves/secp256k1"); | ||
| const sha256_1 = require("@noble/hashes/sha256"); | ||
| const uint8arrays_1 = require("uint8arrays"); | ||
| const const_1 = require("../const"); | ||
| const did = __importStar(require("../did")); | ||
| class Secp256k1Keypair { | ||
| import { secp256k1 as k256 } from '@noble/curves/secp256k1'; | ||
| import { sha256 } from '@noble/hashes/sha256'; | ||
| import { fromString as ui8FromString, toString as ui8ToString, } from 'uint8arrays'; | ||
| import { SECP256K1_JWT_ALG } from '../const.js'; | ||
| import * as did from '../did.js'; | ||
| export class Secp256k1Keypair { | ||
| constructor(privateKey, exportable) { | ||
| Object.defineProperty(this, "privateKey", { | ||
| enumerable: true, | ||
| configurable: true, | ||
| writable: true, | ||
| value: privateKey | ||
| }); | ||
| Object.defineProperty(this, "exportable", { | ||
| enumerable: true, | ||
| configurable: true, | ||
| writable: true, | ||
| value: exportable | ||
| }); | ||
| Object.defineProperty(this, "jwtAlg", { | ||
| enumerable: true, | ||
| configurable: true, | ||
| writable: true, | ||
| value: const_1.SECP256K1_JWT_ALG | ||
| }); | ||
| Object.defineProperty(this, "publicKey", { | ||
| enumerable: true, | ||
| configurable: true, | ||
| writable: true, | ||
| value: void 0 | ||
| }); | ||
| this.publicKey = secp256k1_1.secp256k1.getPublicKey(privateKey); | ||
| this.privateKey = privateKey; | ||
| this.exportable = exportable; | ||
| this.jwtAlg = SECP256K1_JWT_ALG; | ||
| this.publicKey = k256.getPublicKey(privateKey); | ||
| } | ||
| static async create(opts) { | ||
| const { exportable = false } = opts || {}; | ||
| const privKey = secp256k1_1.secp256k1.utils.randomPrivateKey(); | ||
| const privKey = k256.utils.randomPrivateKey(); | ||
| return new Secp256k1Keypair(privKey, exportable); | ||
@@ -77,3 +20,3 @@ } | ||
| const { exportable = false } = opts || {}; | ||
| const privKeyBytes = typeof privKey === 'string' ? (0, uint8arrays_1.fromString)(privKey, 'hex') : privKey; | ||
| const privKeyBytes = typeof privKey === 'string' ? ui8FromString(privKey, 'hex') : privKey; | ||
| return new Secp256k1Keypair(privKeyBytes, exportable); | ||
@@ -85,3 +28,3 @@ } | ||
| publicKeyStr(encoding = 'base64pad') { | ||
| return (0, uint8arrays_1.toString)(this.publicKey, encoding); | ||
| return ui8ToString(this.publicKey, encoding); | ||
| } | ||
@@ -92,5 +35,5 @@ did() { | ||
| async sign(msg) { | ||
| const msgHash = await (0, sha256_1.sha256)(msg); | ||
| const msgHash = await sha256(msg); | ||
| // return raw 64 byte sig not DER-encoded | ||
| const sig = await secp256k1_1.secp256k1.sign(msgHash, this.privateKey, { lowS: true }); | ||
| const sig = await k256.sign(msgHash, this.privateKey, { lowS: true }); | ||
| return sig.toCompactRawBytes(); | ||
@@ -105,3 +48,2 @@ } | ||
| } | ||
| exports.Secp256k1Keypair = Secp256k1Keypair; | ||
| //# sourceMappingURL=keypair.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"keypair.js","sourceRoot":"","sources":["../../src/secp256k1/keypair.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA2D;AAC3D,iDAA6C;AAC7C,6CAGoB;AAEpB,oCAA4C;AAC5C,4CAA6B;AAO7B,MAAa,gBAAgB;IAI3B,YACU,UAAsB,EACtB,UAAmB;QAD3B;;;;mBAAQ,UAAU;WAAY;QAC9B;;;;mBAAQ,UAAU;WAAS;QAL7B;;;;mBAAS,yBAAiB;WAAA;QAClB;;;;;WAAqB;QAM3B,IAAI,CAAC,SAAS,GAAG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AAC,iBAAiB,EAAE,CAAA;IAChC,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;QAClD,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;CACF;AAtDD,4CAsDC","sourcesContent":["import { secp256k1 as k256 } from '@noble/curves/secp256k1'\nimport { sha256 } from '@noble/hashes/sha256'\nimport {\n fromString as ui8FromString,\n toString as ui8ToString,\n} from 'uint8arrays'\nimport { SupportedEncodings } from 'uint8arrays/to-string'\nimport { SECP256K1_JWT_ALG } from '../const'\nimport * as did from '../did'\nimport { Keypair } from '../types'\n\nexport type Secp256k1KeypairOptions = {\n exportable: boolean\n}\n\nexport class Secp256k1Keypair implements Keypair {\n jwtAlg = SECP256K1_JWT_ALG\n private publicKey: Uint8Array\n\n constructor(\n private privateKey: Uint8Array,\n private exportable: boolean,\n ) {\n this.publicKey = k256.getPublicKey(privateKey)\n }\n\n static async create(\n opts?: Partial<Secp256k1KeypairOptions>,\n ): Promise<Secp256k1Keypair> {\n const { exportable = false } = opts || {}\n const privKey = k256.utils.randomPrivateKey()\n return new Secp256k1Keypair(privKey, exportable)\n }\n\n static async import(\n privKey: Uint8Array | string,\n opts?: Partial<Secp256k1KeypairOptions>,\n ): Promise<Secp256k1Keypair> {\n const { exportable = false } = opts || {}\n const privKeyBytes =\n typeof privKey === 'string' ? ui8FromString(privKey, 'hex') : privKey\n return new Secp256k1Keypair(privKeyBytes, exportable)\n }\n\n publicKeyBytes(): Uint8Array {\n return this.publicKey\n }\n\n publicKeyStr(encoding: SupportedEncodings = 'base64pad'): string {\n return ui8ToString(this.publicKey, encoding)\n }\n\n did(): string {\n return did.formatDidKey(this.jwtAlg, this.publicKey)\n }\n\n async sign(msg: Uint8Array): Promise<Uint8Array> {\n const msgHash = await sha256(msg)\n // return raw 64 byte sig not DER-encoded\n const sig = await k256.sign(msgHash, this.privateKey, { lowS: true })\n return sig.toCompactRawBytes()\n }\n\n async export(): Promise<Uint8Array> {\n if (!this.exportable) {\n throw new Error('Private key is not exportable')\n }\n return this.privateKey\n }\n}\n"]} | ||
| {"version":3,"file":"keypair.js","sourceRoot":"","sources":["../../src/secp256k1/keypair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EACL,UAAU,IAAI,aAAa,EAC3B,QAAQ,IAAI,WAAW,GACxB,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,GAAG,MAAM,WAAW,CAAA;AAOhC,MAAM,OAAO,gBAAgB;IAI3B,YACU,UAAsB,EACtB,UAAmB;QADnB,eAAU,GAAV,UAAU,CAAY;QACtB,eAAU,GAAV,UAAU,CAAS;QAL7B,WAAM,GAAG,iBAAiB,CAAA;QAOxB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;IAChD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,IAAuC;QAEvC,MAAM,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,IAAI,IAAI,EAAE,CAAA;QACzC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAA;QAC7C,OAAO,IAAI,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;IAClD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,OAA4B,EAC5B,IAAuC;QAEvC,MAAM,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,IAAI,IAAI,EAAE,CAAA;QACzC,MAAM,YAAY,GAChB,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;QACvE,OAAO,IAAI,gBAAgB,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;IACvD,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;IAED,YAAY,CAAC,WAA+B,WAAW;QACrD,OAAO,WAAW,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;IAC9C,CAAC;IAED,GAAG;QACD,OAAO,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;IACtD,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAe;QACxB,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,CAAA;QACjC,yCAAyC;QACzC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;QACrE,OAAO,GAAG,CAAC,iBAAiB,EAAE,CAAA;IAChC,CAAC;IAED,KAAK,CAAC,MAAM;QACV,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;QAClD,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;CACF","sourcesContent":["import { secp256k1 as k256 } from '@noble/curves/secp256k1'\nimport { sha256 } from '@noble/hashes/sha256'\nimport {\n fromString as ui8FromString,\n toString as ui8ToString,\n} from 'uint8arrays'\nimport { SupportedEncodings } from 'uint8arrays/to-string'\nimport { SECP256K1_JWT_ALG } from '../const.js'\nimport * as did from '../did.js'\nimport { Keypair } from '../types.js'\n\nexport type Secp256k1KeypairOptions = {\n exportable: boolean\n}\n\nexport class Secp256k1Keypair implements Keypair {\n jwtAlg = SECP256K1_JWT_ALG\n private publicKey: Uint8Array\n\n constructor(\n private privateKey: Uint8Array,\n private exportable: boolean,\n ) {\n this.publicKey = k256.getPublicKey(privateKey)\n }\n\n static async create(\n opts?: Partial<Secp256k1KeypairOptions>,\n ): Promise<Secp256k1Keypair> {\n const { exportable = false } = opts || {}\n const privKey = k256.utils.randomPrivateKey()\n return new Secp256k1Keypair(privKey, exportable)\n }\n\n static async import(\n privKey: Uint8Array | string,\n opts?: Partial<Secp256k1KeypairOptions>,\n ): Promise<Secp256k1Keypair> {\n const { exportable = false } = opts || {}\n const privKeyBytes =\n typeof privKey === 'string' ? ui8FromString(privKey, 'hex') : privKey\n return new Secp256k1Keypair(privKeyBytes, exportable)\n }\n\n publicKeyBytes(): Uint8Array {\n return this.publicKey\n }\n\n publicKeyStr(encoding: SupportedEncodings = 'base64pad'): string {\n return ui8ToString(this.publicKey, encoding)\n }\n\n did(): string {\n return did.formatDidKey(this.jwtAlg, this.publicKey)\n }\n\n async sign(msg: Uint8Array): Promise<Uint8Array> {\n const msgHash = await sha256(msg)\n // return raw 64 byte sig not DER-encoded\n const sig = await k256.sign(msgHash, this.privateKey, { lowS: true })\n return sig.toCompactRawBytes()\n }\n\n async export(): Promise<Uint8Array> {\n if (!this.exportable) {\n throw new Error('Private key is not exportable')\n }\n return this.privateKey\n }\n}\n"]} |
@@ -1,2 +0,2 @@ | ||
| import { VerifyOptions } from '../types'; | ||
| import { VerifyOptions } from '../types.js'; | ||
| export declare const verifyDidSig: (did: string, data: Uint8Array, sig: Uint8Array, opts?: VerifyOptions) => Promise<boolean>; | ||
@@ -3,0 +3,0 @@ export declare const verifySig: (publicKey: Uint8Array, data: Uint8Array, sig: Uint8Array, opts?: VerifyOptions) => Promise<boolean>; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/secp256k1/operations.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAGxC,eAAO,MAAM,YAAY,GACvB,KAAK,MAAM,EACX,MAAM,UAAU,EAChB,KAAK,UAAU,EACf,OAAO,aAAa,KACnB,OAAO,CAAC,OAAO,CAOjB,CAAA;AAED,eAAO,MAAM,SAAS,GACpB,WAAW,UAAU,EACrB,MAAM,UAAU,EAChB,KAAK,UAAU,EACf,OAAO,aAAa,KACnB,OAAO,CAAC,OAAO,CAOjB,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,KAAK,UAAU,YAO9C,CAAA"} | ||
| {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/secp256k1/operations.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAG3C,eAAO,MAAM,YAAY,GACvB,KAAK,MAAM,EACX,MAAM,UAAU,EAChB,KAAK,UAAU,EACf,OAAO,aAAa,KACnB,OAAO,CAAC,OAAO,CAOjB,CAAA;AAED,eAAO,MAAM,SAAS,GACpB,WAAW,UAAU,EACrB,MAAM,UAAU,EAChB,KAAK,UAAU,EACf,OAAO,aAAa,KACnB,OAAO,CAAC,OAAO,CAOjB,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,KAAK,UAAU,YAO9C,CAAA"} |
@@ -1,55 +0,18 @@ | ||
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || (function () { | ||
| var ownKeys = function(o) { | ||
| ownKeys = Object.getOwnPropertyNames || function (o) { | ||
| var ar = []; | ||
| for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
| return ar; | ||
| }; | ||
| return ownKeys(o); | ||
| }; | ||
| return function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| })(); | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.isCompactFormat = exports.verifySig = exports.verifyDidSig = void 0; | ||
| const secp256k1_1 = require("@noble/curves/secp256k1"); | ||
| const sha256_1 = require("@noble/hashes/sha256"); | ||
| const ui8 = __importStar(require("uint8arrays")); | ||
| const const_1 = require("../const"); | ||
| const utils_1 = require("../utils"); | ||
| const verifyDidSig = async (did, data, sig, opts) => { | ||
| const prefixedBytes = (0, utils_1.extractPrefixedBytes)((0, utils_1.extractMultikey)(did)); | ||
| if (!(0, utils_1.hasPrefix)(prefixedBytes, const_1.SECP256K1_DID_PREFIX)) { | ||
| import { secp256k1 as k256 } from '@noble/curves/secp256k1'; | ||
| import { sha256 } from '@noble/hashes/sha256'; | ||
| import * as ui8 from 'uint8arrays'; | ||
| import { SECP256K1_DID_PREFIX } from '../const.js'; | ||
| import { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils.js'; | ||
| export const verifyDidSig = async (did, data, sig, opts) => { | ||
| const prefixedBytes = extractPrefixedBytes(extractMultikey(did)); | ||
| if (!hasPrefix(prefixedBytes, SECP256K1_DID_PREFIX)) { | ||
| throw new Error(`Not a secp256k1 did:key: ${did}`); | ||
| } | ||
| const keyBytes = prefixedBytes.slice(const_1.SECP256K1_DID_PREFIX.length); | ||
| return (0, exports.verifySig)(keyBytes, data, sig, opts); | ||
| const keyBytes = prefixedBytes.slice(SECP256K1_DID_PREFIX.length); | ||
| return verifySig(keyBytes, data, sig, opts); | ||
| }; | ||
| exports.verifyDidSig = verifyDidSig; | ||
| const verifySig = async (publicKey, data, sig, opts) => { | ||
| export const verifySig = async (publicKey, data, sig, opts) => { | ||
| const allowMalleable = opts?.allowMalleableSig ?? false; | ||
| const msgHash = await (0, sha256_1.sha256)(data); | ||
| return secp256k1_1.secp256k1.verify(sig, msgHash, publicKey, { | ||
| const msgHash = await sha256(data); | ||
| return k256.verify(sig, msgHash, publicKey, { | ||
| format: allowMalleable ? undefined : 'compact', // prevent DER-encoded signatures | ||
@@ -59,6 +22,5 @@ lowS: !allowMalleable, | ||
| }; | ||
| exports.verifySig = verifySig; | ||
| const isCompactFormat = (sig) => { | ||
| export const isCompactFormat = (sig) => { | ||
| try { | ||
| const parsed = secp256k1_1.secp256k1.Signature.fromCompact(sig); | ||
| const parsed = k256.Signature.fromCompact(sig); | ||
| return ui8.equals(parsed.toCompactRawBytes(), sig); | ||
@@ -70,3 +32,2 @@ } | ||
| }; | ||
| exports.isCompactFormat = isCompactFormat; | ||
| //# sourceMappingURL=operations.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/secp256k1/operations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA2D;AAC3D,iDAA6C;AAC7C,iDAAkC;AAClC,oCAA+C;AAE/C,oCAA2E;AAEpE,MAAM,YAAY,GAAG,KAAK,EAC/B,GAAW,EACX,IAAgB,EAChB,GAAe,EACf,IAAoB,EACF,EAAE;IACpB,MAAM,aAAa,GAAG,IAAA,4BAAoB,EAAC,IAAA,uBAAe,EAAC,GAAG,CAAC,CAAC,CAAA;IAChE,IAAI,CAAC,IAAA,iBAAS,EAAC,aAAa,EAAE,4BAAoB,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,EAAE,CAAC,CAAA;IACpD,CAAC;IACD,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,4BAAoB,CAAC,MAAM,CAAC,CAAA;IACjE,OAAO,IAAA,iBAAS,EAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;AAC7C,CAAC,CAAA;AAZY,QAAA,YAAY,gBAYxB;AAEM,MAAM,SAAS,GAAG,KAAK,EAC5B,SAAqB,EACrB,IAAgB,EAChB,GAAe,EACf,IAAoB,EACF,EAAE;IACpB,MAAM,cAAc,GAAG,IAAI,EAAE,iBAAiB,IAAI,KAAK,CAAA;IACvD,MAAM,OAAO,GAAG,MAAM,IAAA,eAAM,EAAC,IAAI,CAAC,CAAA;IAClC,OAAO,qBAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE;QAC1C,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,iCAAiC;QACjF,IAAI,EAAE,CAAC,cAAc;KACtB,CAAC,CAAA;AACJ,CAAC,CAAA;AAZY,QAAA,SAAS,aAYrB;AAEM,MAAM,eAAe,GAAG,CAAC,GAAe,EAAE,EAAE;IACjD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,qBAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;QAC9C,OAAO,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,EAAE,GAAG,CAAC,CAAA;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA;AAPY,QAAA,eAAe,mBAO3B","sourcesContent":["import { secp256k1 as k256 } from '@noble/curves/secp256k1'\nimport { sha256 } from '@noble/hashes/sha256'\nimport * as ui8 from 'uint8arrays'\nimport { SECP256K1_DID_PREFIX } from '../const'\nimport { VerifyOptions } from '../types'\nimport { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils'\n\nexport const verifyDidSig = async (\n did: string,\n data: Uint8Array,\n sig: Uint8Array,\n opts?: VerifyOptions,\n): Promise<boolean> => {\n const prefixedBytes = extractPrefixedBytes(extractMultikey(did))\n if (!hasPrefix(prefixedBytes, SECP256K1_DID_PREFIX)) {\n throw new Error(`Not a secp256k1 did:key: ${did}`)\n }\n const keyBytes = prefixedBytes.slice(SECP256K1_DID_PREFIX.length)\n return verifySig(keyBytes, data, sig, opts)\n}\n\nexport const verifySig = async (\n publicKey: Uint8Array,\n data: Uint8Array,\n sig: Uint8Array,\n opts?: VerifyOptions,\n): Promise<boolean> => {\n const allowMalleable = opts?.allowMalleableSig ?? false\n const msgHash = await sha256(data)\n return k256.verify(sig, msgHash, publicKey, {\n format: allowMalleable ? undefined : 'compact', // prevent DER-encoded signatures\n lowS: !allowMalleable,\n })\n}\n\nexport const isCompactFormat = (sig: Uint8Array) => {\n try {\n const parsed = k256.Signature.fromCompact(sig)\n return ui8.equals(parsed.toCompactRawBytes(), sig)\n } catch {\n return false\n }\n}\n"]} | ||
| {"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/secp256k1/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,KAAK,GAAG,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE9E,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,GAAW,EACX,IAAgB,EAChB,GAAe,EACf,IAAoB,EACF,EAAE;IACpB,MAAM,aAAa,GAAG,oBAAoB,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAA;IAChE,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,oBAAoB,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,EAAE,CAAC,CAAA;IACpD,CAAC;IACD,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAA;IACjE,OAAO,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;AAC7C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAC5B,SAAqB,EACrB,IAAgB,EAChB,GAAe,EACf,IAAoB,EACF,EAAE;IACpB,MAAM,cAAc,GAAG,IAAI,EAAE,iBAAiB,IAAI,KAAK,CAAA;IACvD,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAA;IAClC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE;QAC1C,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,iCAAiC;QACjF,IAAI,EAAE,CAAC,cAAc;KACtB,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAe,EAAE,EAAE;IACjD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;QAC9C,OAAO,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,EAAE,GAAG,CAAC,CAAA;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { secp256k1 as k256 } from '@noble/curves/secp256k1'\nimport { sha256 } from '@noble/hashes/sha256'\nimport * as ui8 from 'uint8arrays'\nimport { SECP256K1_DID_PREFIX } from '../const.js'\nimport { VerifyOptions } from '../types.js'\nimport { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils.js'\n\nexport const verifyDidSig = async (\n did: string,\n data: Uint8Array,\n sig: Uint8Array,\n opts?: VerifyOptions,\n): Promise<boolean> => {\n const prefixedBytes = extractPrefixedBytes(extractMultikey(did))\n if (!hasPrefix(prefixedBytes, SECP256K1_DID_PREFIX)) {\n throw new Error(`Not a secp256k1 did:key: ${did}`)\n }\n const keyBytes = prefixedBytes.slice(SECP256K1_DID_PREFIX.length)\n return verifySig(keyBytes, data, sig, opts)\n}\n\nexport const verifySig = async (\n publicKey: Uint8Array,\n data: Uint8Array,\n sig: Uint8Array,\n opts?: VerifyOptions,\n): Promise<boolean> => {\n const allowMalleable = opts?.allowMalleableSig ?? false\n const msgHash = await sha256(data)\n return k256.verify(sig, msgHash, publicKey, {\n format: allowMalleable ? undefined : 'compact', // prevent DER-encoded signatures\n lowS: !allowMalleable,\n })\n}\n\nexport const isCompactFormat = (sig: Uint8Array) => {\n try {\n const parsed = k256.Signature.fromCompact(sig)\n return ui8.equals(parsed.toCompactRawBytes(), sig)\n } catch {\n return false\n }\n}\n"]} |
@@ -1,3 +0,3 @@ | ||
| import { DidKeyPlugin } from '../types'; | ||
| import { DidKeyPlugin } from '../types.js'; | ||
| export declare const secp256k1Plugin: DidKeyPlugin; | ||
| //# sourceMappingURL=plugin.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/secp256k1/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAIvC,eAAO,MAAM,eAAe,EAAE,YAO7B,CAAA"} | ||
| {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/secp256k1/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI1C,eAAO,MAAM,eAAe,EAAE,YAO7B,CAAA"} |
@@ -1,14 +0,11 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.secp256k1Plugin = void 0; | ||
| const const_1 = require("../const"); | ||
| const encoding_1 = require("./encoding"); | ||
| const operations_1 = require("./operations"); | ||
| exports.secp256k1Plugin = { | ||
| prefix: const_1.SECP256K1_DID_PREFIX, | ||
| jwtAlg: const_1.SECP256K1_JWT_ALG, | ||
| verifySignature: operations_1.verifyDidSig, | ||
| compressPubkey: encoding_1.compressPubkey, | ||
| decompressPubkey: encoding_1.decompressPubkey, | ||
| import { SECP256K1_DID_PREFIX, SECP256K1_JWT_ALG } from '../const.js'; | ||
| import { compressPubkey, decompressPubkey } from './encoding.js'; | ||
| import { verifyDidSig } from './operations.js'; | ||
| export const secp256k1Plugin = { | ||
| prefix: SECP256K1_DID_PREFIX, | ||
| jwtAlg: SECP256K1_JWT_ALG, | ||
| verifySignature: verifyDidSig, | ||
| compressPubkey, | ||
| decompressPubkey, | ||
| }; | ||
| //# sourceMappingURL=plugin.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/secp256k1/plugin.ts"],"names":[],"mappings":";;;AAAA,oCAAkE;AAElE,yCAA6D;AAC7D,6CAA2C;AAE9B,QAAA,eAAe,GAAiB;IAC3C,MAAM,EAAE,4BAAoB;IAC5B,MAAM,EAAE,yBAAiB;IACzB,eAAe,EAAE,yBAAY;IAE7B,cAAc,EAAd,yBAAc;IACd,gBAAgB,EAAhB,2BAAgB;CACjB,CAAA","sourcesContent":["import { SECP256K1_DID_PREFIX, SECP256K1_JWT_ALG } from '../const'\nimport { DidKeyPlugin } from '../types'\nimport { compressPubkey, decompressPubkey } from './encoding'\nimport { verifyDidSig } from './operations'\n\nexport const secp256k1Plugin: DidKeyPlugin = {\n prefix: SECP256K1_DID_PREFIX,\n jwtAlg: SECP256K1_JWT_ALG,\n verifySignature: verifyDidSig,\n\n compressPubkey,\n decompressPubkey,\n}\n"]} | ||
| {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/secp256k1/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAErE,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,MAAM,CAAC,MAAM,eAAe,GAAiB;IAC3C,MAAM,EAAE,oBAAoB;IAC5B,MAAM,EAAE,iBAAiB;IACzB,eAAe,EAAE,YAAY;IAE7B,cAAc;IACd,gBAAgB;CACjB,CAAA","sourcesContent":["import { SECP256K1_DID_PREFIX, SECP256K1_JWT_ALG } from '../const.js'\nimport { DidKeyPlugin } from '../types.js'\nimport { compressPubkey, decompressPubkey } from './encoding.js'\nimport { verifyDidSig } from './operations.js'\n\nexport const secp256k1Plugin: DidKeyPlugin = {\n prefix: SECP256K1_DID_PREFIX,\n jwtAlg: SECP256K1_JWT_ALG,\n verifySignature: verifyDidSig,\n\n compressPubkey,\n decompressPubkey,\n}\n"]} |
+5
-43
@@ -1,52 +0,14 @@ | ||
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || (function () { | ||
| var ownKeys = function(o) { | ||
| ownKeys = Object.getOwnPropertyNames || function (o) { | ||
| var ar = []; | ||
| for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
| return ar; | ||
| }; | ||
| return ownKeys(o); | ||
| }; | ||
| return function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| })(); | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.sha256Hex = exports.sha256 = void 0; | ||
| const noble = __importStar(require("@noble/hashes/sha256")); | ||
| const uint8arrays = __importStar(require("uint8arrays")); | ||
| import * as noble from '@noble/hashes/sha256'; | ||
| import * as uint8arrays from 'uint8arrays'; | ||
| // takes either bytes of utf8 input | ||
| // @TODO this can be sync | ||
| const sha256 = async (input) => { | ||
| export const sha256 = async (input) => { | ||
| const bytes = typeof input === 'string' ? uint8arrays.fromString(input, 'utf8') : input; | ||
| return noble.sha256(bytes); | ||
| }; | ||
| exports.sha256 = sha256; | ||
| // @TODO this can be sync | ||
| const sha256Hex = async (input) => { | ||
| const hash = await (0, exports.sha256)(input); | ||
| export const sha256Hex = async (input) => { | ||
| const hash = await sha256(input); | ||
| return uint8arrays.toString(hash, 'hex'); | ||
| }; | ||
| exports.sha256Hex = sha256Hex; | ||
| //# sourceMappingURL=sha.js.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"sha.js","sourceRoot":"","sources":["../src/sha.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA6C;AAC7C,yDAA0C;AAE1C,mCAAmC;AACnC,yBAAyB;AAClB,MAAM,MAAM,GAAG,KAAK,EACzB,KAA0B,EACL,EAAE;IACvB,MAAM,KAAK,GACT,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;IAC3E,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC,CAAA;AANY,QAAA,MAAM,UAMlB;AAED,yBAAyB;AAClB,MAAM,SAAS,GAAG,KAAK,EAC5B,KAA0B,EACT,EAAE;IACnB,MAAM,IAAI,GAAG,MAAM,IAAA,cAAM,EAAC,KAAK,CAAC,CAAA;IAChC,OAAO,WAAW,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;AAC1C,CAAC,CAAA;AALY,QAAA,SAAS,aAKrB","sourcesContent":["import * as noble from '@noble/hashes/sha256'\nimport * as uint8arrays from 'uint8arrays'\n\n// takes either bytes of utf8 input\n// @TODO this can be sync\nexport const sha256 = async (\n input: Uint8Array | string,\n): Promise<Uint8Array> => {\n const bytes =\n typeof input === 'string' ? uint8arrays.fromString(input, 'utf8') : input\n return noble.sha256(bytes)\n}\n\n// @TODO this can be sync\nexport const sha256Hex = async (\n input: Uint8Array | string,\n): Promise<string> => {\n const hash = await sha256(input)\n return uint8arrays.toString(hash, 'hex')\n}\n"]} | ||
| {"version":3,"file":"sha.js","sourceRoot":"","sources":["../src/sha.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,sBAAsB,CAAA;AAC7C,OAAO,KAAK,WAAW,MAAM,aAAa,CAAA;AAE1C,mCAAmC;AACnC,yBAAyB;AACzB,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EACzB,KAA0B,EACL,EAAE;IACvB,MAAM,KAAK,GACT,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;IAC3E,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC5B,CAAC,CAAA;AAED,yBAAyB;AACzB,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAC5B,KAA0B,EACT,EAAE;IACnB,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,CAAA;IAChC,OAAO,WAAW,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;AAC1C,CAAC,CAAA","sourcesContent":["import * as noble from '@noble/hashes/sha256'\nimport * as uint8arrays from 'uint8arrays'\n\n// takes either bytes of utf8 input\n// @TODO this can be sync\nexport const sha256 = async (\n input: Uint8Array | string,\n): Promise<Uint8Array> => {\n const bytes =\n typeof input === 'string' ? uint8arrays.fromString(input, 'utf8') : input\n return noble.sha256(bytes)\n}\n\n// @TODO this can be sync\nexport const sha256Hex = async (\n input: Uint8Array | string,\n): Promise<string> => {\n const hash = await sha256(input)\n return uint8arrays.toString(hash, 'hex')\n}\n"]} |
+1
-2
@@ -1,3 +0,2 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| export {}; | ||
| //# sourceMappingURL=types.js.map |
+9
-48
@@ -1,57 +0,18 @@ | ||
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || (function () { | ||
| var ownKeys = function(o) { | ||
| ownKeys = Object.getOwnPropertyNames || function (o) { | ||
| var ar = []; | ||
| for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
| return ar; | ||
| }; | ||
| return ownKeys(o); | ||
| }; | ||
| return function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| })(); | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.hasPrefix = exports.extractPrefixedBytes = exports.extractMultikey = void 0; | ||
| const uint8arrays = __importStar(require("uint8arrays")); | ||
| const const_1 = require("./const"); | ||
| const extractMultikey = (did) => { | ||
| if (!did.startsWith(const_1.DID_KEY_PREFIX)) { | ||
| import * as uint8arrays from 'uint8arrays'; | ||
| import { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const.js'; | ||
| export const extractMultikey = (did) => { | ||
| if (!did.startsWith(DID_KEY_PREFIX)) { | ||
| throw new Error(`Incorrect prefix for did:key: ${did}`); | ||
| } | ||
| return did.slice(const_1.DID_KEY_PREFIX.length); | ||
| return did.slice(DID_KEY_PREFIX.length); | ||
| }; | ||
| exports.extractMultikey = extractMultikey; | ||
| const extractPrefixedBytes = (multikey) => { | ||
| if (!multikey.startsWith(const_1.BASE58_MULTIBASE_PREFIX)) { | ||
| export const extractPrefixedBytes = (multikey) => { | ||
| if (!multikey.startsWith(BASE58_MULTIBASE_PREFIX)) { | ||
| throw new Error(`Incorrect prefix for multikey: ${multikey}`); | ||
| } | ||
| return uint8arrays.fromString(multikey.slice(const_1.BASE58_MULTIBASE_PREFIX.length), 'base58btc'); | ||
| return uint8arrays.fromString(multikey.slice(BASE58_MULTIBASE_PREFIX.length), 'base58btc'); | ||
| }; | ||
| exports.extractPrefixedBytes = extractPrefixedBytes; | ||
| const hasPrefix = (bytes, prefix) => { | ||
| export const hasPrefix = (bytes, prefix) => { | ||
| return uint8arrays.equals(prefix, bytes.subarray(0, prefix.byteLength)); | ||
| }; | ||
| exports.hasPrefix = hasPrefix; | ||
| //# sourceMappingURL=utils.js.map |
@@ -1,1 +0,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","sourcesContent":["import * as uint8arrays from 'uint8arrays'\nimport { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const'\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"]} | ||
| {"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"]} |
+1
-1
@@ -1,2 +0,2 @@ | ||
| import { VerifyOptions } from './types'; | ||
| import { VerifyOptions } from './types.js'; | ||
| export declare const verifySignature: (didKey: string, data: Uint8Array, sig: Uint8Array, opts?: VerifyOptions & { | ||
@@ -3,0 +3,0 @@ jwtAlg?: string; |
@@ -1,1 +0,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,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"} | ||
| {"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"} |
+8
-46
@@ -1,46 +0,10 @@ | ||
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || (function () { | ||
| var ownKeys = function(o) { | ||
| ownKeys = Object.getOwnPropertyNames || function (o) { | ||
| var ar = []; | ||
| for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
| return ar; | ||
| }; | ||
| return ownKeys(o); | ||
| }; | ||
| return function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| })(); | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.verifySignatureUtf8 = exports.verifySignature = void 0; | ||
| const uint8arrays = __importStar(require("uint8arrays")); | ||
| const did_1 = require("./did"); | ||
| const plugins_1 = require("./plugins"); | ||
| const verifySignature = (didKey, data, sig, opts) => { | ||
| const parsed = (0, did_1.parseDidKey)(didKey); | ||
| import * as uint8arrays from 'uint8arrays'; | ||
| import { parseDidKey } from './did.js'; | ||
| import { plugins } from './plugins.js'; | ||
| export const verifySignature = (didKey, data, sig, opts) => { | ||
| const parsed = parseDidKey(didKey); | ||
| if (opts?.jwtAlg && opts.jwtAlg !== parsed.jwtAlg) { | ||
| throw new Error(`Expected key alg ${opts.jwtAlg}, got ${parsed.jwtAlg}`); | ||
| } | ||
| const plugin = plugins_1.plugins.find((p) => p.jwtAlg === parsed.jwtAlg); | ||
| const plugin = plugins.find((p) => p.jwtAlg === parsed.jwtAlg); | ||
| if (!plugin) { | ||
@@ -51,9 +15,7 @@ throw new Error(`Unsupported signature alg: ${parsed.jwtAlg}`); | ||
| }; | ||
| exports.verifySignature = verifySignature; | ||
| const verifySignatureUtf8 = async (didKey, data, sig, opts) => { | ||
| export const verifySignatureUtf8 = async (didKey, data, sig, opts) => { | ||
| const dataBytes = uint8arrays.fromString(data, 'utf8'); | ||
| const sigBytes = uint8arrays.fromString(sig, 'base64url'); | ||
| return (0, exports.verifySignature)(didKey, dataBytes, sigBytes, opts); | ||
| return verifySignature(didKey, dataBytes, sigBytes, opts); | ||
| }; | ||
| exports.verifySignatureUtf8 = verifySignatureUtf8; | ||
| //# sourceMappingURL=verify.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"verify.js","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mapp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ays from 'uint8arrays'\nimport { parseDidKey } from './did'\nimport { plugins } from './plugins'\nimport { VerifyOptions } from './types'\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"]} | ||
| {"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
-1
| Dual MIT/Apache-2.0 License | ||
| Copyright (c) 2022-2025 Bluesky Social PBC, and Contributors | ||
| Copyright (c) 2022-2026 Bluesky Social PBC, and Contributors | ||
@@ -5,0 +5,0 @@ Except as otherwise noted in individual files, this software is licensed under the MIT license (<http://opensource.org/licenses/MIT>), or the Apache License, Version 2.0 (<http://www.apache.org/licenses/LICENSE-2.0>). |
+14
-9
| { | ||
| "name": "@atproto/crypto", | ||
| "version": "0.4.5", | ||
| "version": "0.5.0-next.0", | ||
| "license": "MIT", | ||
@@ -16,6 +16,4 @@ "description": "Library for cryptographic keys and signing in atproto", | ||
| }, | ||
| "main": "dist/index.js", | ||
| "types": "dist/index.d.ts", | ||
| "engines": { | ||
| "node": ">=18.7.0" | ||
| "node": ">=22" | ||
| }, | ||
@@ -25,13 +23,20 @@ "dependencies": { | ||
| "@noble/hashes": "^1.6.1", | ||
| "uint8arrays": "3.0.0" | ||
| "uint8arrays": "^5.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "jest": "^28.1.2", | ||
| "typescript": "^5.6.3", | ||
| "@atproto/common": "^0.5.2" | ||
| "jest": "^30.0.0", | ||
| "typescript": "^6.0.3", | ||
| "@atproto/common": "^0.6.0-next.0" | ||
| }, | ||
| "type": "module", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "test": "jest ", | ||
| "test": "NODE_OPTIONS=--experimental-vm-modules jest", | ||
| "build": "tsc --build tsconfig.build.json" | ||
| } | ||
| } |
+3
-3
| import * as uint8arrays from 'uint8arrays' | ||
| import { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const' | ||
| import { plugins } from './plugins' | ||
| import { extractMultikey, extractPrefixedBytes, hasPrefix } from './utils' | ||
| import { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const.js' | ||
| import { plugins } from './plugins.js' | ||
| import { extractMultikey, extractPrefixedBytes, hasPrefix } from './utils.js' | ||
@@ -6,0 +6,0 @@ export type ParsedMultikey = { |
+12
-12
@@ -1,14 +0,14 @@ | ||
| export * from './const' | ||
| export * from './did' | ||
| export * from './multibase' | ||
| export * from './random' | ||
| export * from './sha' | ||
| export * from './types' | ||
| export * from './verify' | ||
| export * from './utils' | ||
| export * from './const.js' | ||
| export * from './did.js' | ||
| export * from './multibase.js' | ||
| export * from './random.js' | ||
| export * from './sha.js' | ||
| export * from './types.js' | ||
| export * from './verify.js' | ||
| export * from './utils.js' | ||
| export * from './p256/keypair' | ||
| export * from './p256/plugin' | ||
| export * from './p256/keypair.js' | ||
| export * from './p256/plugin.js' | ||
| export * from './secp256k1/keypair' | ||
| export * from './secp256k1/plugin' | ||
| export * from './secp256k1/keypair.js' | ||
| export * from './secp256k1/plugin.js' |
@@ -8,5 +8,5 @@ import { p256 } from '@noble/curves/p256' | ||
| import { SupportedEncodings } from 'uint8arrays/to-string' | ||
| import { P256_JWT_ALG } from '../const' | ||
| import * as did from '../did' | ||
| import { Keypair } from '../types' | ||
| import { P256_JWT_ALG } from '../const.js' | ||
| import * as did from '../did.js' | ||
| import { Keypair } from '../types.js' | ||
@@ -13,0 +13,0 @@ export type P256KeypairOptions = { |
| import { p256 } from '@noble/curves/p256' | ||
| import { sha256 } from '@noble/hashes/sha256' | ||
| import { equals as ui8equals } from 'uint8arrays' | ||
| import { P256_DID_PREFIX } from '../const' | ||
| import { VerifyOptions } from '../types' | ||
| import { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils' | ||
| import { P256_DID_PREFIX } from '../const.js' | ||
| import { VerifyOptions } from '../types.js' | ||
| import { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils.js' | ||
@@ -8,0 +8,0 @@ export const verifyDidSig = async ( |
@@ -1,5 +0,5 @@ | ||
| import { P256_DID_PREFIX, P256_JWT_ALG } from '../const' | ||
| import { DidKeyPlugin } from '../types' | ||
| import { compressPubkey, decompressPubkey } from './encoding' | ||
| import { verifyDidSig } from './operations' | ||
| import { P256_DID_PREFIX, P256_JWT_ALG } from '../const.js' | ||
| import { DidKeyPlugin } from '../types.js' | ||
| import { compressPubkey, decompressPubkey } from './encoding.js' | ||
| import { verifyDidSig } from './operations.js' | ||
@@ -6,0 +6,0 @@ export const p256Plugin: DidKeyPlugin = { |
+2
-2
@@ -1,4 +0,4 @@ | ||
| import { p256Plugin } from './p256/plugin' | ||
| import { secp256k1Plugin } from './secp256k1/plugin' | ||
| import { p256Plugin } from './p256/plugin.js' | ||
| import { secp256k1Plugin } from './secp256k1/plugin.js' | ||
| export const plugins = [p256Plugin, secp256k1Plugin] |
+4
-2
| import * as noble from '@noble/hashes/utils' | ||
| import * as uint8arrays from 'uint8arrays' | ||
| import { SupportedEncodings } from 'uint8arrays/to-string' | ||
| import { sha256 } from './sha' | ||
| import { sha256 } from './sha.js' | ||
| export const randomBytes = noble.randomBytes | ||
| export const randomBytes = noble.randomBytes as ( | ||
| bytesLength?: number, | ||
| ) => Uint8Array<ArrayBuffer> | ||
@@ -8,0 +10,0 @@ export const randomStr = ( |
@@ -8,5 +8,5 @@ import { secp256k1 as k256 } from '@noble/curves/secp256k1' | ||
| import { SupportedEncodings } from 'uint8arrays/to-string' | ||
| import { SECP256K1_JWT_ALG } from '../const' | ||
| import * as did from '../did' | ||
| import { Keypair } from '../types' | ||
| import { SECP256K1_JWT_ALG } from '../const.js' | ||
| import * as did from '../did.js' | ||
| import { Keypair } from '../types.js' | ||
@@ -13,0 +13,0 @@ export type Secp256k1KeypairOptions = { |
| import { secp256k1 as k256 } from '@noble/curves/secp256k1' | ||
| import { sha256 } from '@noble/hashes/sha256' | ||
| import * as ui8 from 'uint8arrays' | ||
| import { SECP256K1_DID_PREFIX } from '../const' | ||
| import { VerifyOptions } from '../types' | ||
| import { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils' | ||
| import { SECP256K1_DID_PREFIX } from '../const.js' | ||
| import { VerifyOptions } from '../types.js' | ||
| import { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils.js' | ||
@@ -8,0 +8,0 @@ export const verifyDidSig = async ( |
@@ -1,5 +0,5 @@ | ||
| import { SECP256K1_DID_PREFIX, SECP256K1_JWT_ALG } from '../const' | ||
| import { DidKeyPlugin } from '../types' | ||
| import { compressPubkey, decompressPubkey } from './encoding' | ||
| import { verifyDidSig } from './operations' | ||
| import { SECP256K1_DID_PREFIX, SECP256K1_JWT_ALG } from '../const.js' | ||
| import { DidKeyPlugin } from '../types.js' | ||
| import { compressPubkey, decompressPubkey } from './encoding.js' | ||
| import { verifyDidSig } from './operations.js' | ||
@@ -6,0 +6,0 @@ export const secp256k1Plugin: DidKeyPlugin = { |
+1
-1
| import * as uint8arrays from 'uint8arrays' | ||
| import { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const' | ||
| import { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const.js' | ||
@@ -4,0 +4,0 @@ export const extractMultikey = (did: string): string => { |
+3
-3
| import * as uint8arrays from 'uint8arrays' | ||
| import { parseDidKey } from './did' | ||
| import { plugins } from './plugins' | ||
| import { VerifyOptions } from './types' | ||
| import { parseDidKey } from './did.js' | ||
| import { plugins } from './plugins.js' | ||
| import { VerifyOptions } from './types.js' | ||
@@ -6,0 +6,0 @@ export const verifySignature = ( |
+13
-4
| import * as uint8arrays from 'uint8arrays' | ||
| import { P256Keypair, Secp256k1Keypair } from '../src' | ||
| import * as did from '../src/did' | ||
| import * as did from '../src/did.js' | ||
| import { P256Keypair, Secp256k1Keypair } from '../src/index.js' | ||
| import { decompressPubkey as p256Decompress } from '../src/p256/encoding.js' | ||
| import { decompressPubkey as secp256k1Decompress } from '../src/secp256k1/encoding.js' | ||
@@ -21,3 +23,8 @@ describe('secp256k1 did:key', () => { | ||
| expect(jwtAlg).toBe('ES256K') | ||
| expect(uint8arrays.equals(keyBytes, keypair.publicKeyBytes())).toBeTruthy | ||
| expect( | ||
| uint8arrays.equals( | ||
| keyBytes, | ||
| secp256k1Decompress(keypair.publicKeyBytes()), | ||
| ), | ||
| ).toBeTruthy() | ||
| } | ||
@@ -45,3 +52,5 @@ }) | ||
| expect(jwtAlg).toBe('ES256') | ||
| expect(uint8arrays.equals(keyBytes, keypair.publicKeyBytes())).toBeTruthy | ||
| expect( | ||
| uint8arrays.equals(keyBytes, p256Decompress(keypair.publicKeyBytes())), | ||
| ).toBeTruthy() | ||
| } | ||
@@ -48,0 +57,0 @@ }) |
@@ -1,6 +0,6 @@ | ||
| import * as did from '../src/did' | ||
| import * as p256Encoding from '../src/p256/encoding' | ||
| import { P256Keypair } from '../src/p256/keypair' | ||
| import * as secpEncoding from '../src/secp256k1/encoding' | ||
| import { Secp256k1Keypair } from '../src/secp256k1/keypair' | ||
| import * as did from '../src/did.js' | ||
| import * as p256Encoding from '../src/p256/encoding.js' | ||
| import { P256Keypair } from '../src/p256/keypair.js' | ||
| import * as secpEncoding from '../src/secp256k1/encoding.js' | ||
| import { Secp256k1Keypair } from '../src/secp256k1/keypair.js' | ||
@@ -7,0 +7,0 @@ describe('public key compression', () => { |
@@ -1,6 +0,6 @@ | ||
| import { randomBytes } from '../src' | ||
| import { P256Keypair } from '../src/p256/keypair' | ||
| import * as p256 from '../src/p256/operations' | ||
| import { Secp256k1Keypair } from '../src/secp256k1/keypair' | ||
| import * as secp from '../src/secp256k1/operations' | ||
| import { randomBytes } from '../src/index.js' | ||
| import { P256Keypair } from '../src/p256/keypair.js' | ||
| import * as p256 from '../src/p256/operations.js' | ||
| import { Secp256k1Keypair } from '../src/secp256k1/keypair.js' | ||
| import * as secp from '../src/secp256k1/operations.js' | ||
@@ -7,0 +7,0 @@ describe('keypairs', () => { |
@@ -1,2 +0,2 @@ | ||
| import { randomIntFromSeed } from '../src' | ||
| import { randomIntFromSeed } from '../src/index.js' | ||
@@ -3,0 +3,0 @@ describe('randomIntFromSeed()', () => { |
@@ -1,4 +0,4 @@ | ||
| /* eslint-disable import/no-deprecated */ | ||
| import fs from 'node:fs' | ||
| import path from 'node:path' | ||
| import { fileURLToPath } from 'node:url' | ||
| import { p256 as nobleP256 } from '@noble/curves/p256' | ||
@@ -15,8 +15,10 @@ import { secp256k1 as nobleK256 } from '@noble/curves/secp256k1' | ||
| sha256, | ||
| } from '../src' | ||
| import { P256Keypair } from '../src/p256/keypair' | ||
| import * as p256 from '../src/p256/operations' | ||
| import { Secp256k1Keypair } from '../src/secp256k1/keypair' | ||
| import * as secp from '../src/secp256k1/operations' | ||
| } from '../src/index.js' | ||
| import { P256Keypair } from '../src/p256/keypair.js' | ||
| import * as p256 from '../src/p256/operations.js' | ||
| import { Secp256k1Keypair } from '../src/secp256k1/keypair.js' | ||
| import * as secp from '../src/secp256k1/operations.js' | ||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
| describe('signatures', () => { | ||
@@ -23,0 +25,0 @@ let vectors: TestVector[] |
| /** @type {import('jest').Config} */ | ||
| module.exports = { | ||
| displayName: 'Crypto', | ||
| transform: { '^.+\\.(t|j)s$': '@swc/jest' }, | ||
| setupFiles: ['<rootDir>/../../jest.setup.ts'], | ||
| moduleNameMapper: { '^(\\.\\.?\\/.+)\\.js$': ['$1.ts', '$1.js'] }, | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Yes
NaN104619
-12.36%104
-0.95%1507
-21.47%+ Added
+ Added
- Removed
- Removed
Updated