@mysten/signers 0.1.13 → 0.1.14

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,13 @@
1
1
  # @mysten/signers
2
2
 
3
+ ## 0.1.14
4
+
5
+ ### Patch Changes
6
+
7
+ - 5217cab: Fix signature not having lowS enforced
8
+ - a08ead6: Add webcrypto to the files allowlist
9
+ - b34f523: Fix re-constructing signers from exported bytes, and introduce import / export methods
10
+
3
11
  ## 0.1.13
4
12
 
5
13
  ### Patch Changes
@@ -1,14 +1,20 @@
1
1
  import type { SignatureScheme } from '@mysten/sui/cryptography';
2
2
  import { Signer } from '@mysten/sui/cryptography';
3
3
  import { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';
4
+ export interface ExportedWebCryptoKeypair {
5
+ privateKey: CryptoKey;
6
+ publicKey: Uint8Array;
7
+ }
4
8
  export declare class WebCryptoSigner extends Signer {
5
9
  #private;
6
10
  privateKey: CryptoKey;
7
11
  static generate({ extractable }?: {
8
12
  extractable?: boolean;
9
13
  }): Promise<WebCryptoSigner>;
14
+ static import(data: ExportedWebCryptoKeypair): WebCryptoSigner;
10
15
  getKeyScheme(): SignatureScheme;
11
16
  constructor(privateKey: CryptoKey, publicKey: Uint8Array);
17
+ export(): ExportedWebCryptoKeypair;
12
18
  getPublicKey(): Secp256r1PublicKey;
13
19
  sign(bytes: Uint8Array): Promise<Uint8Array>;
14
20
  }
@@ -30,6 +30,7 @@ __export(webcrypto_exports, {
30
30
  module.exports = __toCommonJS(webcrypto_exports);
31
31
  var import_cryptography = require("@mysten/sui/cryptography");
32
32
  var import_secp256r1 = require("@mysten/sui/keypairs/secp256r1");
33
+ var import_p256 = require("@noble/curves/p256");
33
34
  var _publicKey;
34
35
  function getCompressedPublicKey(publicKey) {
35
36
  const rawBytes = new Uint8Array(publicKey);
@@ -46,7 +47,7 @@ const _WebCryptoSigner = class _WebCryptoSigner extends import_cryptography.Sign
46
47
  super();
47
48
  __privateAdd(this, _publicKey);
48
49
  this.privateKey = privateKey;
49
- __privateSet(this, _publicKey, new import_secp256r1.Secp256r1PublicKey(getCompressedPublicKey(publicKey)));
50
+ __privateSet(this, _publicKey, new import_secp256r1.Secp256r1PublicKey(publicKey));
50
51
  }
51
52
  static async generate({ extractable = false } = {}) {
52
53
  const keypair = await globalThis.crypto.subtle.generateKey(
@@ -58,16 +59,29 @@ const _WebCryptoSigner = class _WebCryptoSigner extends import_cryptography.Sign
58
59
  ["sign", "verify"]
59
60
  );
60
61
  const publicKey = await globalThis.crypto.subtle.exportKey("raw", keypair.publicKey);
61
- return new _WebCryptoSigner(keypair.privateKey, new Uint8Array(publicKey));
62
+ return new _WebCryptoSigner(
63
+ keypair.privateKey,
64
+ getCompressedPublicKey(new Uint8Array(publicKey))
65
+ );
66
+ }
67
+ static import(data) {
68
+ return new _WebCryptoSigner(data.privateKey, data.publicKey);
62
69
  }
63
70
  getKeyScheme() {
64
71
  return "Secp256r1";
65
72
  }
73
+ // Exports the keypair to store in IndexedDB.
74
+ export() {
75
+ return {
76
+ privateKey: this.privateKey,
77
+ publicKey: __privateGet(this, _publicKey).toRawBytes()
78
+ };
79
+ }
66
80
  getPublicKey() {
67
81
  return __privateGet(this, _publicKey);
68
82
  }
69
83
  async sign(bytes) {
70
- const signature = await globalThis.crypto.subtle.sign(
84
+ const rawSignature = await globalThis.crypto.subtle.sign(
71
85
  {
72
86
  name: "ECDSA",
73
87
  hash: "SHA-256"
@@ -75,7 +89,8 @@ const _WebCryptoSigner = class _WebCryptoSigner extends import_cryptography.Sign
75
89
  this.privateKey,
76
90
  bytes
77
91
  );
78
- return new Uint8Array(signature);
92
+ const signature = import_p256.secp256r1.Signature.fromCompact(new Uint8Array(rawSignature));
93
+ return signature.normalizeS().toCompactRawBytes();
79
94
  }
80
95
  };
81
96
  _publicKey = new WeakMap();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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: '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AAY,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;",
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';\nimport { secp256r1 } from '@noble/curves/p256';\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 interface ExportedWebCryptoKeypair {\n\tprivateKey: CryptoKey;\n\tpublicKey: Uint8Array;\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(\n\t\t\tkeypair.privateKey,\n\t\t\tgetCompressedPublicKey(new Uint8Array(publicKey)),\n\t\t);\n\t}\n\n\tstatic import(data: ExportedWebCryptoKeypair) {\n\t\treturn new WebCryptoSigner(data.privateKey, data.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(publicKey);\n\t}\n\n\t// Exports the keypair to store in IndexedDB.\n\texport(): ExportedWebCryptoKeypair {\n\t\t// TODO: Should we add something like `toJSON` on this so that if you attempt to serialize it throws?\n\t\treturn {\n\t\t\tprivateKey: this.privateKey,\n\t\t\tpublicKey: this.#publicKey.toRawBytes(),\n\t\t};\n\t}\n\n\tgetPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n\n\tasync sign(bytes: Uint8Array): Promise<Uint8Array> {\n\t\tconst rawSignature = 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\tconst signature = secp256r1.Signature.fromCompact(new Uint8Array(rawSignature));\n\n\t\treturn signature.normalizeS().toCompactRawBytes();\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,0BAAuB;AACvB,uBAAmC;AACnC,kBAA0B;AAN1B;AASA,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;AAOO,MAAM,mBAAN,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';
2
2
  import { Signer } from '@mysten/sui/cryptography';
3
3
  import { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';
4
+ export interface ExportedWebCryptoKeypair {
5
+ privateKey: CryptoKey;
6
+ publicKey: Uint8Array;
7
+ }
4
8
  export declare class WebCryptoSigner extends Signer {
5
9
  #private;
6
10
  privateKey: CryptoKey;
7
11
  static generate({ extractable }?: {
8
12
  extractable?: boolean;
9
13
  }): Promise<WebCryptoSigner>;
14
+ static import(data: ExportedWebCryptoKeypair): WebCryptoSigner;
10
15
  getKeyScheme(): SignatureScheme;
11
16
  constructor(privateKey: CryptoKey, publicKey: Uint8Array);
17
+ export(): ExportedWebCryptoKeypair;
12
18
  getPublicKey(): Secp256r1PublicKey;
13
19
  sign(bytes: Uint8Array): Promise<Uint8Array>;
14
20
  }
@@ -8,6 +8,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
8
8
  var _publicKey;
9
9
  import { Signer } from "@mysten/sui/cryptography";
10
10
  import { Secp256r1PublicKey } from "@mysten/sui/keypairs/secp256r1";
11
+ import { secp256r1 } from "@noble/curves/p256";
11
12
  function getCompressedPublicKey(publicKey) {
12
13
  const rawBytes = new Uint8Array(publicKey);
13
14
  const x = rawBytes.slice(1, 33);
@@ -23,7 +24,7 @@ const _WebCryptoSigner = class _WebCryptoSigner extends Signer {
23
24
  super();
24
25
  __privateAdd(this, _publicKey);
25
26
  this.privateKey = privateKey;
26
- __privateSet(this, _publicKey, new Secp256r1PublicKey(getCompressedPublicKey(publicKey)));
27
+ __privateSet(this, _publicKey, new Secp256r1PublicKey(publicKey));
27
28
  }
28
29
  static async generate({ extractable = false } = {}) {
29
30
  const keypair = await globalThis.crypto.subtle.generateKey(
@@ -35,16 +36,29 @@ const _WebCryptoSigner = class _WebCryptoSigner extends Signer {
35
36
  ["sign", "verify"]
36
37
  );
37
38
  const publicKey = await globalThis.crypto.subtle.exportKey("raw", keypair.publicKey);
38
- return new _WebCryptoSigner(keypair.privateKey, new Uint8Array(publicKey));
39
+ return new _WebCryptoSigner(
40
+ keypair.privateKey,
41
+ getCompressedPublicKey(new Uint8Array(publicKey))
42
+ );
43
+ }
44
+ static import(data) {
45
+ return new _WebCryptoSigner(data.privateKey, data.publicKey);
39
46
  }
40
47
  getKeyScheme() {
41
48
  return "Secp256r1";
42
49
  }
50
+ // Exports the keypair to store in IndexedDB.
51
+ export() {
52
+ return {
53
+ privateKey: this.privateKey,
54
+ publicKey: __privateGet(this, _publicKey).toRawBytes()
55
+ };
56
+ }
43
57
  getPublicKey() {
44
58
  return __privateGet(this, _publicKey);
45
59
  }
46
60
  async sign(bytes) {
47
- const signature = await globalThis.crypto.subtle.sign(
61
+ const rawSignature = await globalThis.crypto.subtle.sign(
48
62
  {
49
63
  name: "ECDSA",
50
64
  hash: "SHA-256"
@@ -52,7 +66,8 @@ const _WebCryptoSigner = class _WebCryptoSigner extends Signer {
52
66
  this.privateKey,
53
67
  bytes
54
68
  );
55
- return new Uint8Array(signature);
69
+ const signature = secp256r1.Signature.fromCompact(new Uint8Array(rawSignature));
70
+ return signature.normalizeS().toCompactRawBytes();
56
71
  }
57
72
  };
58
73
  _publicKey = new WeakMap();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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;",
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';\nimport { secp256r1 } from '@noble/curves/p256';\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 interface ExportedWebCryptoKeypair {\n\tprivateKey: CryptoKey;\n\tpublicKey: Uint8Array;\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(\n\t\t\tkeypair.privateKey,\n\t\t\tgetCompressedPublicKey(new Uint8Array(publicKey)),\n\t\t);\n\t}\n\n\tstatic import(data: ExportedWebCryptoKeypair) {\n\t\treturn new WebCryptoSigner(data.privateKey, data.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(publicKey);\n\t}\n\n\t// Exports the keypair to store in IndexedDB.\n\texport(): ExportedWebCryptoKeypair {\n\t\t// TODO: Should we add something like `toJSON` on this so that if you attempt to serialize it throws?\n\t\treturn {\n\t\t\tprivateKey: this.privateKey,\n\t\t\tpublicKey: this.#publicKey.toRawBytes(),\n\t\t};\n\t}\n\n\tgetPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n\n\tasync sign(bytes: Uint8Array): Promise<Uint8Array> {\n\t\tconst rawSignature = 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\tconst signature = secp256r1.Signature.fromCompact(new Uint8Array(rawSignature));\n\n\t\treturn signature.normalizeS().toCompactRawBytes();\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;AAAA;AAIA,SAAS,cAAc;AACvB,SAAS,0BAA0B;AACnC,SAAS,iBAAiB;AAG1B,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;AAOO,MAAM,mBAAN,MAAM,yBAAwB,OAAO;AAAA,EA+B3C,YAAY,YAAuB,WAAuB;AACzD,UAAM;AA7BP;AA8BC,SAAK,aAAa;AAClB,uBAAK,YAAa,IAAI,mBAAmB,SAAS;AAAA,EACnD;AAAA,EA9BA,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;AAAA,MACV,QAAQ;AAAA,MACR,uBAAuB,IAAI,WAAW,SAAS,CAAC;AAAA,IACjD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