@mysten/signers 0.1.11 → 0.1.13

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @mysten/signers
2
2
 
3
+ ## 0.1.13
4
+
5
+ ### Patch Changes
6
+
7
+ - 1e87d03: Add new WebCrypto signer
8
+
9
+ ## 0.1.12
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [cf3d12d]
14
+ - @mysten/sui@1.24.0
15
+
3
16
  ## 0.1.11
4
17
 
5
18
  ### Patch Changes
@@ -0,0 +1,14 @@
1
+ import type { SignatureScheme } from '@mysten/sui/cryptography';
2
+ import { Signer } from '@mysten/sui/cryptography';
3
+ import { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';
4
+ export declare class WebCryptoSigner extends Signer {
5
+ #private;
6
+ privateKey: CryptoKey;
7
+ static generate({ extractable }?: {
8
+ extractable?: boolean;
9
+ }): Promise<WebCryptoSigner>;
10
+ getKeyScheme(): SignatureScheme;
11
+ constructor(privateKey: CryptoKey, publicKey: Uint8Array);
12
+ getPublicKey(): Secp256r1PublicKey;
13
+ sign(bytes: Uint8Array): Promise<Uint8Array>;
14
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
23
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
24
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
26
+ var webcrypto_exports = {};
27
+ __export(webcrypto_exports, {
28
+ WebCryptoSigner: () => WebCryptoSigner
29
+ });
30
+ module.exports = __toCommonJS(webcrypto_exports);
31
+ var import_cryptography = require("@mysten/sui/cryptography");
32
+ var import_secp256r1 = require("@mysten/sui/keypairs/secp256r1");
33
+ var _publicKey;
34
+ function getCompressedPublicKey(publicKey) {
35
+ const rawBytes = new Uint8Array(publicKey);
36
+ const x = rawBytes.slice(1, 33);
37
+ const y = rawBytes.slice(33, 65);
38
+ const prefix = (y[31] & 1) === 0 ? 2 : 3;
39
+ const compressed = new Uint8Array(import_secp256r1.Secp256r1PublicKey.SIZE);
40
+ compressed[0] = prefix;
41
+ compressed.set(x, 1);
42
+ return compressed;
43
+ }
44
+ const _WebCryptoSigner = class _WebCryptoSigner extends import_cryptography.Signer {
45
+ constructor(privateKey, publicKey) {
46
+ super();
47
+ __privateAdd(this, _publicKey);
48
+ this.privateKey = privateKey;
49
+ __privateSet(this, _publicKey, new import_secp256r1.Secp256r1PublicKey(getCompressedPublicKey(publicKey)));
50
+ }
51
+ static async generate({ extractable = false } = {}) {
52
+ const keypair = await globalThis.crypto.subtle.generateKey(
53
+ {
54
+ name: "ECDSA",
55
+ namedCurve: "P-256"
56
+ },
57
+ extractable,
58
+ ["sign", "verify"]
59
+ );
60
+ const publicKey = await globalThis.crypto.subtle.exportKey("raw", keypair.publicKey);
61
+ return new _WebCryptoSigner(keypair.privateKey, new Uint8Array(publicKey));
62
+ }
63
+ getKeyScheme() {
64
+ return "Secp256r1";
65
+ }
66
+ getPublicKey() {
67
+ return __privateGet(this, _publicKey);
68
+ }
69
+ async sign(bytes) {
70
+ const signature = await globalThis.crypto.subtle.sign(
71
+ {
72
+ name: "ECDSA",
73
+ hash: "SHA-256"
74
+ },
75
+ this.privateKey,
76
+ bytes
77
+ );
78
+ return new Uint8Array(signature);
79
+ }
80
+ };
81
+ _publicKey = new WeakMap();
82
+ let WebCryptoSigner = _WebCryptoSigner;
83
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/webcrypto/index.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SignatureScheme } from '@mysten/sui/cryptography';\nimport { Signer } from '@mysten/sui/cryptography';\nimport { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';\n\n// Convert from uncompressed (65 bytes) to compressed (33 bytes) format\nfunction getCompressedPublicKey(publicKey: Uint8Array) {\n\tconst rawBytes = new Uint8Array(publicKey);\n\tconst x = rawBytes.slice(1, 33);\n\tconst y = rawBytes.slice(33, 65);\n\n\tconst prefix = (y[31] & 1) === 0 ? 0x02 : 0x03;\n\n\tconst compressed = new Uint8Array(Secp256r1PublicKey.SIZE);\n\tcompressed[0] = prefix;\n\tcompressed.set(x, 1);\n\n\treturn compressed;\n}\n\nexport class WebCryptoSigner extends Signer {\n\tprivateKey: CryptoKey;\n\n\t#publicKey: Secp256r1PublicKey;\n\n\tstatic async generate({ extractable = false }: { extractable?: boolean } = {}) {\n\t\tconst keypair = await globalThis.crypto.subtle.generateKey(\n\t\t\t{\n\t\t\t\tname: 'ECDSA',\n\t\t\t\tnamedCurve: 'P-256',\n\t\t\t},\n\t\t\textractable,\n\t\t\t['sign', 'verify'],\n\t\t);\n\n\t\tconst publicKey = await globalThis.crypto.subtle.exportKey('raw', keypair.publicKey);\n\n\t\treturn new WebCryptoSigner(keypair.privateKey, new Uint8Array(publicKey));\n\t}\n\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Secp256r1';\n\t}\n\n\tconstructor(privateKey: CryptoKey, publicKey: Uint8Array) {\n\t\tsuper();\n\t\tthis.privateKey = privateKey;\n\t\tthis.#publicKey = new Secp256r1PublicKey(getCompressedPublicKey(publicKey));\n\t}\n\n\tgetPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n\n\tasync sign(bytes: Uint8Array): Promise<Uint8Array> {\n\t\tconst signature = await globalThis.crypto.subtle.sign(\n\t\t\t{\n\t\t\t\tname: 'ECDSA',\n\t\t\t\thash: 'SHA-256',\n\t\t\t},\n\t\t\tthis.privateKey,\n\t\t\tbytes,\n\t\t);\n\n\t\treturn new Uint8Array(signature);\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,0BAAuB;AACvB,uBAAmC;AALnC;AAQA,SAAS,uBAAuB,WAAuB;AACtD,QAAM,WAAW,IAAI,WAAW,SAAS;AACzC,QAAM,IAAI,SAAS,MAAM,GAAG,EAAE;AAC9B,QAAM,IAAI,SAAS,MAAM,IAAI,EAAE;AAE/B,QAAM,UAAU,EAAE,EAAE,IAAI,OAAO,IAAI,IAAO;AAE1C,QAAM,aAAa,IAAI,WAAW,oCAAmB,IAAI;AACzD,aAAW,CAAC,IAAI;AAChB,aAAW,IAAI,GAAG,CAAC;AAEnB,SAAO;AACR;AAEO,MAAM,mBAAN,MAAM,yBAAwB,2BAAO;AAAA,EAwB3C,YAAY,YAAuB,WAAuB;AACzD,UAAM;AAtBP;AAuBC,SAAK,aAAa;AAClB,uBAAK,YAAa,IAAI,oCAAmB,uBAAuB,SAAS,CAAC;AAAA,EAC3E;AAAA,EAvBA,aAAa,SAAS,EAAE,cAAc,MAAM,IAA+B,CAAC,GAAG;AAC9E,UAAM,UAAU,MAAM,WAAW,OAAO,OAAO;AAAA,MAC9C;AAAA,QACC,MAAM;AAAA,QACN,YAAY;AAAA,MACb;AAAA,MACA;AAAA,MACA,CAAC,QAAQ,QAAQ;AAAA,IAClB;AAEA,UAAM,YAAY,MAAM,WAAW,OAAO,OAAO,UAAU,OAAO,QAAQ,SAAS;AAEnF,WAAO,IAAI,iBAAgB,QAAQ,YAAY,IAAI,WAAW,SAAS,CAAC;AAAA,EACzE;AAAA,EAEA,eAAgC;AAC/B,WAAO;AAAA,EACR;AAAA,EAQA,eAAe;AACd,WAAO,mBAAK;AAAA,EACb;AAAA,EAEA,MAAM,KAAK,OAAwC;AAClD,UAAM,YAAY,MAAM,WAAW,OAAO,OAAO;AAAA,MAChD;AAAA,QACC,MAAM;AAAA,QACN,MAAM;AAAA,MACP;AAAA,MACA,KAAK;AAAA,MACL;AAAA,IACD;AAEA,WAAO,IAAI,WAAW,SAAS;AAAA,EAChC;AACD;AA3CC;AAHM,IAAM,kBAAN;",
6
+ "names": []
7
+ }
@@ -0,0 +1,14 @@
1
+ import type { SignatureScheme } from '@mysten/sui/cryptography';
2
+ import { Signer } from '@mysten/sui/cryptography';
3
+ import { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';
4
+ export declare class WebCryptoSigner extends Signer {
5
+ #private;
6
+ privateKey: CryptoKey;
7
+ static generate({ extractable }?: {
8
+ extractable?: boolean;
9
+ }): Promise<WebCryptoSigner>;
10
+ getKeyScheme(): SignatureScheme;
11
+ constructor(privateKey: CryptoKey, publicKey: Uint8Array);
12
+ getPublicKey(): Secp256r1PublicKey;
13
+ sign(bytes: Uint8Array): Promise<Uint8Array>;
14
+ }
@@ -0,0 +1,63 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+ var _publicKey;
9
+ import { Signer } from "@mysten/sui/cryptography";
10
+ import { Secp256r1PublicKey } from "@mysten/sui/keypairs/secp256r1";
11
+ function getCompressedPublicKey(publicKey) {
12
+ const rawBytes = new Uint8Array(publicKey);
13
+ const x = rawBytes.slice(1, 33);
14
+ const y = rawBytes.slice(33, 65);
15
+ const prefix = (y[31] & 1) === 0 ? 2 : 3;
16
+ const compressed = new Uint8Array(Secp256r1PublicKey.SIZE);
17
+ compressed[0] = prefix;
18
+ compressed.set(x, 1);
19
+ return compressed;
20
+ }
21
+ const _WebCryptoSigner = class _WebCryptoSigner extends Signer {
22
+ constructor(privateKey, publicKey) {
23
+ super();
24
+ __privateAdd(this, _publicKey);
25
+ this.privateKey = privateKey;
26
+ __privateSet(this, _publicKey, new Secp256r1PublicKey(getCompressedPublicKey(publicKey)));
27
+ }
28
+ static async generate({ extractable = false } = {}) {
29
+ const keypair = await globalThis.crypto.subtle.generateKey(
30
+ {
31
+ name: "ECDSA",
32
+ namedCurve: "P-256"
33
+ },
34
+ extractable,
35
+ ["sign", "verify"]
36
+ );
37
+ const publicKey = await globalThis.crypto.subtle.exportKey("raw", keypair.publicKey);
38
+ return new _WebCryptoSigner(keypair.privateKey, new Uint8Array(publicKey));
39
+ }
40
+ getKeyScheme() {
41
+ return "Secp256r1";
42
+ }
43
+ getPublicKey() {
44
+ return __privateGet(this, _publicKey);
45
+ }
46
+ async sign(bytes) {
47
+ const signature = await globalThis.crypto.subtle.sign(
48
+ {
49
+ name: "ECDSA",
50
+ hash: "SHA-256"
51
+ },
52
+ this.privateKey,
53
+ bytes
54
+ );
55
+ return new Uint8Array(signature);
56
+ }
57
+ };
58
+ _publicKey = new WeakMap();
59
+ let WebCryptoSigner = _WebCryptoSigner;
60
+ export {
61
+ WebCryptoSigner
62
+ };
63
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/webcrypto/index.ts"],
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SignatureScheme } from '@mysten/sui/cryptography';\nimport { Signer } from '@mysten/sui/cryptography';\nimport { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';\n\n// Convert from uncompressed (65 bytes) to compressed (33 bytes) format\nfunction getCompressedPublicKey(publicKey: Uint8Array) {\n\tconst rawBytes = new Uint8Array(publicKey);\n\tconst x = rawBytes.slice(1, 33);\n\tconst y = rawBytes.slice(33, 65);\n\n\tconst prefix = (y[31] & 1) === 0 ? 0x02 : 0x03;\n\n\tconst compressed = new Uint8Array(Secp256r1PublicKey.SIZE);\n\tcompressed[0] = prefix;\n\tcompressed.set(x, 1);\n\n\treturn compressed;\n}\n\nexport class WebCryptoSigner extends Signer {\n\tprivateKey: CryptoKey;\n\n\t#publicKey: Secp256r1PublicKey;\n\n\tstatic async generate({ extractable = false }: { extractable?: boolean } = {}) {\n\t\tconst keypair = await globalThis.crypto.subtle.generateKey(\n\t\t\t{\n\t\t\t\tname: 'ECDSA',\n\t\t\t\tnamedCurve: 'P-256',\n\t\t\t},\n\t\t\textractable,\n\t\t\t['sign', 'verify'],\n\t\t);\n\n\t\tconst publicKey = await globalThis.crypto.subtle.exportKey('raw', keypair.publicKey);\n\n\t\treturn new WebCryptoSigner(keypair.privateKey, new Uint8Array(publicKey));\n\t}\n\n\tgetKeyScheme(): SignatureScheme {\n\t\treturn 'Secp256r1';\n\t}\n\n\tconstructor(privateKey: CryptoKey, publicKey: Uint8Array) {\n\t\tsuper();\n\t\tthis.privateKey = privateKey;\n\t\tthis.#publicKey = new Secp256r1PublicKey(getCompressedPublicKey(publicKey));\n\t}\n\n\tgetPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n\n\tasync sign(bytes: Uint8Array): Promise<Uint8Array> {\n\t\tconst signature = await globalThis.crypto.subtle.sign(\n\t\t\t{\n\t\t\t\tname: 'ECDSA',\n\t\t\t\thash: 'SHA-256',\n\t\t\t},\n\t\t\tthis.privateKey,\n\t\t\tbytes,\n\t\t);\n\n\t\treturn new Uint8Array(signature);\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;AAAA;AAIA,SAAS,cAAc;AACvB,SAAS,0BAA0B;AAGnC,SAAS,uBAAuB,WAAuB;AACtD,QAAM,WAAW,IAAI,WAAW,SAAS;AACzC,QAAM,IAAI,SAAS,MAAM,GAAG,EAAE;AAC9B,QAAM,IAAI,SAAS,MAAM,IAAI,EAAE;AAE/B,QAAM,UAAU,EAAE,EAAE,IAAI,OAAO,IAAI,IAAO;AAE1C,QAAM,aAAa,IAAI,WAAW,mBAAmB,IAAI;AACzD,aAAW,CAAC,IAAI;AAChB,aAAW,IAAI,GAAG,CAAC;AAEnB,SAAO;AACR;AAEO,MAAM,mBAAN,MAAM,yBAAwB,OAAO;AAAA,EAwB3C,YAAY,YAAuB,WAAuB;AACzD,UAAM;AAtBP;AAuBC,SAAK,aAAa;AAClB,uBAAK,YAAa,IAAI,mBAAmB,uBAAuB,SAAS,CAAC;AAAA,EAC3E;AAAA,EAvBA,aAAa,SAAS,EAAE,cAAc,MAAM,IAA+B,CAAC,GAAG;AAC9E,UAAM,UAAU,MAAM,WAAW,OAAO,OAAO;AAAA,MAC9C;AAAA,QACC,MAAM;AAAA,QACN,YAAY;AAAA,MACb;AAAA,MACA;AAAA,MACA,CAAC,QAAQ,QAAQ;AAAA,IAClB;AAEA,UAAM,YAAY,MAAM,WAAW,OAAO,OAAO,UAAU,OAAO,QAAQ,SAAS;AAEnF,WAAO,IAAI,iBAAgB,QAAQ,YAAY,IAAI,WAAW,SAAS,CAAC;AAAA,EACzE;AAAA,EAEA,eAAgC;AAC/B,WAAO;AAAA,EACR;AAAA,EAQA,eAAe;AACd,WAAO,mBAAK;AAAA,EACb;AAAA,EAEA,MAAM,KAAK,OAAwC;AAClD,UAAM,YAAY,MAAM,WAAW,OAAO,OAAO;AAAA,MAChD;AAAA,QACC,MAAM;AAAA,QACN,MAAM;AAAA,MACP;AAAA,MACA,KAAK;AAAA,MACL;AAAA,IACD;AAEA,WAAO,IAAI,WAAW,SAAS;AAAA,EAChC;AACD;AA3CC;AAHM,IAAM,kBAAN;",
6
+ "names": []
7
+ }