@atproto/crypto 0.4.4 → 0.5.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/LICENSE.txt +1 -1
- package/dist/const.d.ts +2 -2
- package/dist/const.d.ts.map +1 -1
- package/dist/const.js +6 -9
- package/dist/const.js.map +1 -1
- package/dist/did.d.ts +1 -1
- package/dist/did.d.ts.map +1 -1
- package/dist/did.js +16 -46
- package/dist/did.js.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -28
- package/dist/index.js.map +1 -1
- package/dist/multibase.d.ts.map +1 -1
- package/dist/multibase.js +3 -31
- package/dist/multibase.js.map +1 -1
- package/dist/p256/encoding.d.ts.map +1 -1
- package/dist/p256/encoding.js +5 -10
- package/dist/p256/encoding.js.map +1 -1
- package/dist/p256/keypair.d.ts +1 -1
- package/dist/p256/keypair.d.ts.map +1 -1
- package/dist/p256/keypair.js +15 -63
- package/dist/p256/keypair.js.map +1 -1
- package/dist/p256/operations.d.ts +1 -1
- package/dist/p256/operations.d.ts.map +1 -1
- package/dist/p256/operations.js +16 -22
- package/dist/p256/operations.js.map +1 -1
- package/dist/p256/plugin.d.ts +1 -1
- package/dist/p256/plugin.d.ts.map +1 -1
- package/dist/p256/plugin.js +9 -12
- package/dist/p256/plugin.js.map +1 -1
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +3 -6
- package/dist/plugins.js.map +1 -1
- package/dist/random.d.ts +1 -2
- package/dist/random.d.ts.map +1 -1
- package/dist/random.js +8 -36
- package/dist/random.js.map +1 -1
- package/dist/secp256k1/encoding.d.ts.map +1 -1
- package/dist/secp256k1/encoding.js +5 -10
- package/dist/secp256k1/encoding.js.map +1 -1
- package/dist/secp256k1/keypair.d.ts +1 -1
- package/dist/secp256k1/keypair.d.ts.map +1 -1
- package/dist/secp256k1/keypair.js +15 -63
- package/dist/secp256k1/keypair.js.map +1 -1
- package/dist/secp256k1/operations.d.ts +1 -1
- package/dist/secp256k1/operations.d.ts.map +1 -1
- package/dist/secp256k1/operations.js +15 -44
- package/dist/secp256k1/operations.js.map +1 -1
- package/dist/secp256k1/plugin.d.ts +1 -1
- package/dist/secp256k1/plugin.d.ts.map +1 -1
- package/dist/secp256k1/plugin.js +9 -12
- package/dist/secp256k1/plugin.js.map +1 -1
- package/dist/sha.d.ts.map +1 -1
- package/dist/sha.js +5 -33
- package/dist/sha.js.map +1 -1
- package/dist/types.js +1 -2
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -38
- package/dist/utils.js.map +1 -1
- package/dist/verify.d.ts +1 -1
- package/dist/verify.d.ts.map +1 -1
- package/dist/verify.js +8 -36
- package/dist/verify.js.map +1 -1
- package/jest.config.cjs +14 -0
- package/package.json +14 -9
- package/src/did.ts +8 -5
- package/src/index.ts +12 -12
- package/src/p256/keypair.ts +3 -3
- package/src/p256/operations.ts +3 -3
- package/src/p256/plugin.ts +4 -4
- package/src/plugins.ts +2 -2
- package/src/random.ts +4 -2
- package/src/secp256k1/keypair.ts +3 -3
- package/src/secp256k1/operations.ts +3 -3
- package/src/secp256k1/plugin.ts +4 -4
- package/src/utils.ts +1 -1
- package/src/verify.ts +3 -3
- package/tests/did.test.ts +13 -4
- package/tests/key-compression.test.ts +5 -5
- package/tests/keypairs.test.ts +5 -5
- package/tests/random.test.ts +2 -2
- package/tests/signatures.test.ts +9 -5
- package/tsconfig.build.tsbuildinfo +1 -1
- package/jest.config.js +0 -6
- package/tsconfig.tests.tsbuildinfo +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/p256/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"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"}
|
package/dist/p256/plugin.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
verifySignature: operations_1.verifyDidSig,
|
|
11
|
-
compressPubkey: encoding_1.compressPubkey,
|
|
12
|
-
decompressPubkey: encoding_1.decompressPubkey,
|
|
1
|
+
import { P256_DID_PREFIX, P256_JWT_ALG } from '../const.js';
|
|
2
|
+
import { compressPubkey, decompressPubkey } from './encoding.js';
|
|
3
|
+
import { verifyDidSig } from './operations.js';
|
|
4
|
+
export const p256Plugin = {
|
|
5
|
+
prefix: P256_DID_PREFIX,
|
|
6
|
+
jwtAlg: P256_JWT_ALG,
|
|
7
|
+
verifySignature: verifyDidSig,
|
|
8
|
+
compressPubkey,
|
|
9
|
+
decompressPubkey,
|
|
13
10
|
};
|
|
14
11
|
//# sourceMappingURL=plugin.js.map
|
package/dist/p256/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/p256/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"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"]}
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const plugins: import("./types").DidKeyPlugin[];
|
|
1
|
+
export declare const plugins: import("./types.js").DidKeyPlugin[];
|
|
2
2
|
//# sourceMappingURL=plugins.d.ts.map
|
package/dist/plugins.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,qCAAgC,CAAA"}
|
package/dist/plugins.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const plugin_1 = require("./p256/plugin");
|
|
5
|
-
const plugin_2 = require("./secp256k1/plugin");
|
|
6
|
-
exports.plugins = [plugin_1.p256Plugin, plugin_2.secp256k1Plugin];
|
|
1
|
+
import { p256Plugin } from './p256/plugin.js';
|
|
2
|
+
import { secp256k1Plugin } from './secp256k1/plugin.js';
|
|
3
|
+
export const plugins = [p256Plugin, secp256k1Plugin];
|
|
7
4
|
//# sourceMappingURL=plugins.js.map
|
package/dist/plugins.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"
|
|
1
|
+
{"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"]}
|
package/dist/random.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as noble from '@noble/hashes/utils';
|
|
2
1
|
import { SupportedEncodings } from 'uint8arrays/to-string';
|
|
3
|
-
export declare const randomBytes:
|
|
2
|
+
export declare const randomBytes: (bytesLength?: number) => Uint8Array<ArrayBuffer>;
|
|
4
3
|
export declare const randomStr: (byteLength: number, encoding: SupportedEncodings) => string;
|
|
5
4
|
export declare const randomIntFromSeed: (seed: string, high: number, low?: number) => Promise<number>;
|
|
6
5
|
//# sourceMappingURL=random.d.ts.map
|
package/dist/random.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"
|
|
1
|
+
{"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"}
|
package/dist/random.js
CHANGED
|
@@ -1,44 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.randomIntFromSeed = exports.randomStr = exports.randomBytes = void 0;
|
|
27
|
-
const noble = __importStar(require("@noble/hashes/utils"));
|
|
28
|
-
const uint8arrays = __importStar(require("uint8arrays"));
|
|
29
|
-
const sha_1 = require("./sha");
|
|
30
|
-
exports.randomBytes = noble.randomBytes;
|
|
31
|
-
const randomStr = (byteLength, encoding) => {
|
|
32
|
-
const bytes = (0, exports.randomBytes)(byteLength);
|
|
1
|
+
import * as noble from '@noble/hashes/utils';
|
|
2
|
+
import * as uint8arrays from 'uint8arrays';
|
|
3
|
+
import { sha256 } from './sha.js';
|
|
4
|
+
export const randomBytes = noble.randomBytes;
|
|
5
|
+
export const randomStr = (byteLength, encoding) => {
|
|
6
|
+
const bytes = randomBytes(byteLength);
|
|
33
7
|
return uint8arrays.toString(bytes, encoding);
|
|
34
8
|
};
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const hash = await (0, sha_1.sha256)(seed);
|
|
9
|
+
export const randomIntFromSeed = async (seed, high, low = 0) => {
|
|
10
|
+
const hash = await sha256(seed);
|
|
38
11
|
const number = Buffer.from(hash).readUintBE(0, 6);
|
|
39
12
|
const range = high - low;
|
|
40
13
|
const normalized = number % range;
|
|
41
14
|
return normalized + low;
|
|
42
15
|
};
|
|
43
|
-
exports.randomIntFromSeed = randomIntFromSeed;
|
|
44
16
|
//# sourceMappingURL=random.js.map
|
package/dist/random.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.js","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"
|
|
1
|
+
{"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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/secp256k1/encoding.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/secp256k1/encoding.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,GAAI,aAAa,UAAU,KAAG,UAGxD,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,YAAY,UAAU,KAAG,UAMzD,CAAA"}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
5
|
-
const compressPubkey = (pubkeyBytes) => {
|
|
6
|
-
const point = secp256k1_1.secp256k1.ProjectivePoint.fromHex(pubkeyBytes);
|
|
1
|
+
import { secp256k1 as k256 } from '@noble/curves/secp256k1';
|
|
2
|
+
export const compressPubkey = (pubkeyBytes) => {
|
|
3
|
+
const point = k256.ProjectivePoint.fromHex(pubkeyBytes);
|
|
7
4
|
return point.toRawBytes(true);
|
|
8
5
|
};
|
|
9
|
-
|
|
10
|
-
const decompressPubkey = (compressed) => {
|
|
6
|
+
export const decompressPubkey = (compressed) => {
|
|
11
7
|
if (compressed.length !== 33) {
|
|
12
8
|
throw new Error('Expected 33 byte compress pubkey');
|
|
13
9
|
}
|
|
14
|
-
const point =
|
|
10
|
+
const point = k256.ProjectivePoint.fromHex(compressed);
|
|
15
11
|
return point.toRawBytes(false);
|
|
16
12
|
};
|
|
17
|
-
exports.decompressPubkey = decompressPubkey;
|
|
18
13
|
//# sourceMappingURL=encoding.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/secp256k1/encoding.ts"],"names":[],"mappings":"
|
|
1
|
+
{"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"]}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,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,85 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Secp256k1Keypair = void 0;
|
|
27
|
-
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
28
|
-
const sha256_1 = require("@noble/hashes/sha256");
|
|
29
|
-
const uint8arrays_1 = require("uint8arrays");
|
|
30
|
-
const const_1 = require("../const");
|
|
31
|
-
const did = __importStar(require("../did"));
|
|
32
|
-
class Secp256k1Keypair {
|
|
1
|
+
import { secp256k1 as k256 } from '@noble/curves/secp256k1';
|
|
2
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
3
|
+
import { fromString as ui8FromString, toString as ui8ToString, } from 'uint8arrays';
|
|
4
|
+
import { SECP256K1_JWT_ALG } from '../const.js';
|
|
5
|
+
import * as did from '../did.js';
|
|
6
|
+
export class Secp256k1Keypair {
|
|
33
7
|
constructor(privateKey, exportable) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
value: privateKey
|
|
39
|
-
});
|
|
40
|
-
Object.defineProperty(this, "exportable", {
|
|
41
|
-
enumerable: true,
|
|
42
|
-
configurable: true,
|
|
43
|
-
writable: true,
|
|
44
|
-
value: exportable
|
|
45
|
-
});
|
|
46
|
-
Object.defineProperty(this, "jwtAlg", {
|
|
47
|
-
enumerable: true,
|
|
48
|
-
configurable: true,
|
|
49
|
-
writable: true,
|
|
50
|
-
value: const_1.SECP256K1_JWT_ALG
|
|
51
|
-
});
|
|
52
|
-
Object.defineProperty(this, "publicKey", {
|
|
53
|
-
enumerable: true,
|
|
54
|
-
configurable: true,
|
|
55
|
-
writable: true,
|
|
56
|
-
value: void 0
|
|
57
|
-
});
|
|
58
|
-
this.publicKey = secp256k1_1.secp256k1.getPublicKey(privateKey);
|
|
8
|
+
this.privateKey = privateKey;
|
|
9
|
+
this.exportable = exportable;
|
|
10
|
+
this.jwtAlg = SECP256K1_JWT_ALG;
|
|
11
|
+
this.publicKey = k256.getPublicKey(privateKey);
|
|
59
12
|
}
|
|
60
13
|
static async create(opts) {
|
|
61
14
|
const { exportable = false } = opts || {};
|
|
62
|
-
const privKey =
|
|
15
|
+
const privKey = k256.utils.randomPrivateKey();
|
|
63
16
|
return new Secp256k1Keypair(privKey, exportable);
|
|
64
17
|
}
|
|
65
18
|
static async import(privKey, opts) {
|
|
66
19
|
const { exportable = false } = opts || {};
|
|
67
|
-
const privKeyBytes = typeof privKey === 'string' ? (
|
|
20
|
+
const privKeyBytes = typeof privKey === 'string' ? ui8FromString(privKey, 'hex') : privKey;
|
|
68
21
|
return new Secp256k1Keypair(privKeyBytes, exportable);
|
|
69
22
|
}
|
|
70
23
|
publicKeyBytes() {
|
|
71
24
|
return this.publicKey;
|
|
72
25
|
}
|
|
73
26
|
publicKeyStr(encoding = 'base64pad') {
|
|
74
|
-
return (
|
|
27
|
+
return ui8ToString(this.publicKey, encoding);
|
|
75
28
|
}
|
|
76
29
|
did() {
|
|
77
30
|
return did.formatDidKey(this.jwtAlg, this.publicKey);
|
|
78
31
|
}
|
|
79
32
|
async sign(msg) {
|
|
80
|
-
const msgHash = await
|
|
33
|
+
const msgHash = await sha256(msg);
|
|
81
34
|
// return raw 64 byte sig not DER-encoded
|
|
82
|
-
const sig = await
|
|
35
|
+
const sig = await k256.sign(msgHash, this.privateKey, { lowS: true });
|
|
83
36
|
return sig.toCompactRawBytes();
|
|
84
37
|
}
|
|
85
38
|
async export() {
|
|
@@ -89,5 +42,4 @@ class Secp256k1Keypair {
|
|
|
89
42
|
return this.privateKey;
|
|
90
43
|
}
|
|
91
44
|
}
|
|
92
|
-
exports.Secp256k1Keypair = Secp256k1Keypair;
|
|
93
45
|
//# sourceMappingURL=keypair.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keypair.js","sourceRoot":"","sources":["../../src/secp256k1/keypair.ts"],"names":[],"mappings":"
|
|
1
|
+
{"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,4 +1,4 @@
|
|
|
1
|
-
import { VerifyOptions } from '../types';
|
|
1
|
+
import { VerifyOptions } from '../types.js';
|
|
2
2
|
export declare const verifyDidSig: (did: string, data: Uint8Array, sig: Uint8Array, opts?: VerifyOptions) => Promise<boolean>;
|
|
3
3
|
export declare const verifySig: (publicKey: Uint8Array, data: Uint8Array, sig: Uint8Array, opts?: VerifyOptions) => Promise<boolean>;
|
|
4
4
|
export declare const isCompactFormat: (sig: Uint8Array) => boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/secp256k1/operations.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"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,60 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isCompactFormat = exports.verifySig = exports.verifyDidSig = void 0;
|
|
27
|
-
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
28
|
-
const sha256_1 = require("@noble/hashes/sha256");
|
|
29
|
-
const ui8 = __importStar(require("uint8arrays"));
|
|
30
|
-
const const_1 = require("../const");
|
|
31
|
-
const utils_1 = require("../utils");
|
|
32
|
-
const verifyDidSig = async (did, data, sig, opts) => {
|
|
33
|
-
const prefixedBytes = (0, utils_1.extractPrefixedBytes)((0, utils_1.extractMultikey)(did));
|
|
34
|
-
if (!(0, utils_1.hasPrefix)(prefixedBytes, const_1.SECP256K1_DID_PREFIX)) {
|
|
1
|
+
import { secp256k1 as k256 } from '@noble/curves/secp256k1';
|
|
2
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
3
|
+
import * as ui8 from 'uint8arrays';
|
|
4
|
+
import { SECP256K1_DID_PREFIX } from '../const.js';
|
|
5
|
+
import { extractMultikey, extractPrefixedBytes, hasPrefix } from '../utils.js';
|
|
6
|
+
export const verifyDidSig = async (did, data, sig, opts) => {
|
|
7
|
+
const prefixedBytes = extractPrefixedBytes(extractMultikey(did));
|
|
8
|
+
if (!hasPrefix(prefixedBytes, SECP256K1_DID_PREFIX)) {
|
|
35
9
|
throw new Error(`Not a secp256k1 did:key: ${did}`);
|
|
36
10
|
}
|
|
37
|
-
const keyBytes = prefixedBytes.slice(
|
|
38
|
-
return
|
|
11
|
+
const keyBytes = prefixedBytes.slice(SECP256K1_DID_PREFIX.length);
|
|
12
|
+
return verifySig(keyBytes, data, sig, opts);
|
|
39
13
|
};
|
|
40
|
-
|
|
41
|
-
const verifySig = async (publicKey, data, sig, opts) => {
|
|
14
|
+
export const verifySig = async (publicKey, data, sig, opts) => {
|
|
42
15
|
const allowMalleable = opts?.allowMalleableSig ?? false;
|
|
43
|
-
const msgHash = await
|
|
44
|
-
return
|
|
16
|
+
const msgHash = await sha256(data);
|
|
17
|
+
return k256.verify(sig, msgHash, publicKey, {
|
|
45
18
|
format: allowMalleable ? undefined : 'compact', // prevent DER-encoded signatures
|
|
46
19
|
lowS: !allowMalleable,
|
|
47
20
|
});
|
|
48
21
|
};
|
|
49
|
-
|
|
50
|
-
const isCompactFormat = (sig) => {
|
|
22
|
+
export const isCompactFormat = (sig) => {
|
|
51
23
|
try {
|
|
52
|
-
const parsed =
|
|
24
|
+
const parsed = k256.Signature.fromCompact(sig);
|
|
53
25
|
return ui8.equals(parsed.toCompactRawBytes(), sig);
|
|
54
26
|
}
|
|
55
27
|
catch {
|
|
56
28
|
return false;
|
|
57
29
|
}
|
|
58
30
|
};
|
|
59
|
-
exports.isCompactFormat = isCompactFormat;
|
|
60
31
|
//# sourceMappingURL=operations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/secp256k1/operations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/secp256k1/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"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"}
|
package/dist/secp256k1/plugin.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
verifySignature: operations_1.verifyDidSig,
|
|
11
|
-
compressPubkey: encoding_1.compressPubkey,
|
|
12
|
-
decompressPubkey: encoding_1.decompressPubkey,
|
|
1
|
+
import { SECP256K1_DID_PREFIX, SECP256K1_JWT_ALG } from '../const.js';
|
|
2
|
+
import { compressPubkey, decompressPubkey } from './encoding.js';
|
|
3
|
+
import { verifyDidSig } from './operations.js';
|
|
4
|
+
export const secp256k1Plugin = {
|
|
5
|
+
prefix: SECP256K1_DID_PREFIX,
|
|
6
|
+
jwtAlg: SECP256K1_JWT_ALG,
|
|
7
|
+
verifySignature: verifyDidSig,
|
|
8
|
+
compressPubkey,
|
|
9
|
+
decompressPubkey,
|
|
13
10
|
};
|
|
14
11
|
//# sourceMappingURL=plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/secp256k1/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"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"]}
|
package/dist/sha.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha.d.ts","sourceRoot":"","sources":["../src/sha.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"sha.d.ts","sourceRoot":"","sources":["../src/sha.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM,GACjB,OAAO,UAAU,GAAG,MAAM,KACzB,OAAO,CAAC,UAAU,CAIpB,CAAA;AAGD,eAAO,MAAM,SAAS,GACpB,OAAO,UAAU,GAAG,MAAM,KACzB,OAAO,CAAC,MAAM,CAGhB,CAAA"}
|
package/dist/sha.js
CHANGED
|
@@ -1,42 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.sha256Hex = exports.sha256 = void 0;
|
|
27
|
-
const noble = __importStar(require("@noble/hashes/sha256"));
|
|
28
|
-
const uint8arrays = __importStar(require("uint8arrays"));
|
|
1
|
+
import * as noble from '@noble/hashes/sha256';
|
|
2
|
+
import * as uint8arrays from 'uint8arrays';
|
|
29
3
|
// takes either bytes of utf8 input
|
|
30
4
|
// @TODO this can be sync
|
|
31
|
-
const sha256 = async (input) => {
|
|
5
|
+
export const sha256 = async (input) => {
|
|
32
6
|
const bytes = typeof input === 'string' ? uint8arrays.fromString(input, 'utf8') : input;
|
|
33
7
|
return noble.sha256(bytes);
|
|
34
8
|
};
|
|
35
|
-
exports.sha256 = sha256;
|
|
36
9
|
// @TODO this can be sync
|
|
37
|
-
const sha256Hex = async (input) => {
|
|
38
|
-
const hash = await
|
|
10
|
+
export const sha256Hex = async (input) => {
|
|
11
|
+
const hash = await sha256(input);
|
|
39
12
|
return uint8arrays.toString(hash, 'hex');
|
|
40
13
|
};
|
|
41
|
-
exports.sha256Hex = sha256Hex;
|
|
42
14
|
//# sourceMappingURL=sha.js.map
|
package/dist/sha.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sha.js","sourceRoot":"","sources":["../src/sha.ts"],"names":[],"mappings":"
|
|
1
|
+
{"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"]}
|
package/dist/types.js
CHANGED
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export interface Signer {\n jwtAlg: string\n sign(msg: Uint8Array): Promise<Uint8Array>\n}\n\nexport interface Didable {\n did(): string\n}\n\nexport interface Keypair extends Signer, Didable {}\n\nexport interface ExportableKeypair extends Keypair {\n export(): Promise<Uint8Array>\n}\n\nexport type DidKeyPlugin = {\n prefix: Uint8Array\n jwtAlg: string\n verifySignature: (\n did: string,\n msg: Uint8Array,\n data: Uint8Array,\n opts?: VerifyOptions,\n ) => Promise<boolean>\n\n compressPubkey: (uncompressed: Uint8Array) => Uint8Array\n decompressPubkey: (compressed: Uint8Array) => Uint8Array\n}\n\nexport type VerifyOptions = {\n allowMalleableSig?: boolean\n}\n"]}
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,KAAG,MAK7C,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,UAAU,MAAM,KAAG,UAQvD,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,OAAO,UAAU,EAAE,QAAQ,UAAU,KAAG,OAEjE,CAAA"}
|
package/dist/utils.js
CHANGED
|
@@ -1,47 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.hasPrefix = exports.extractPrefixedBytes = exports.extractMultikey = void 0;
|
|
27
|
-
const uint8arrays = __importStar(require("uint8arrays"));
|
|
28
|
-
const const_1 = require("./const");
|
|
29
|
-
const extractMultikey = (did) => {
|
|
30
|
-
if (!did.startsWith(const_1.DID_KEY_PREFIX)) {
|
|
1
|
+
import * as uint8arrays from 'uint8arrays';
|
|
2
|
+
import { BASE58_MULTIBASE_PREFIX, DID_KEY_PREFIX } from './const.js';
|
|
3
|
+
export const extractMultikey = (did) => {
|
|
4
|
+
if (!did.startsWith(DID_KEY_PREFIX)) {
|
|
31
5
|
throw new Error(`Incorrect prefix for did:key: ${did}`);
|
|
32
6
|
}
|
|
33
|
-
return did.slice(
|
|
7
|
+
return did.slice(DID_KEY_PREFIX.length);
|
|
34
8
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (!multikey.startsWith(const_1.BASE58_MULTIBASE_PREFIX)) {
|
|
9
|
+
export const extractPrefixedBytes = (multikey) => {
|
|
10
|
+
if (!multikey.startsWith(BASE58_MULTIBASE_PREFIX)) {
|
|
38
11
|
throw new Error(`Incorrect prefix for multikey: ${multikey}`);
|
|
39
12
|
}
|
|
40
|
-
return uint8arrays.fromString(multikey.slice(
|
|
13
|
+
return uint8arrays.fromString(multikey.slice(BASE58_MULTIBASE_PREFIX.length), 'base58btc');
|
|
41
14
|
};
|
|
42
|
-
|
|
43
|
-
const hasPrefix = (bytes, prefix) => {
|
|
15
|
+
export const hasPrefix = (bytes, prefix) => {
|
|
44
16
|
return uint8arrays.equals(prefix, bytes.subarray(0, prefix.byteLength));
|
|
45
17
|
};
|
|
46
|
-
exports.hasPrefix = hasPrefix;
|
|
47
18
|
//# sourceMappingURL=utils.js.map
|