@haneullabs/signers 0.1.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/CHANGELOG.md +131 -74
  2. package/README.md +7 -4
  3. package/dist/aws/aws-client.d.mts +48 -0
  4. package/dist/aws/aws-client.d.mts.map +1 -0
  5. package/dist/aws/aws-client.mjs +46 -0
  6. package/dist/aws/aws-client.mjs.map +1 -0
  7. package/dist/aws/aws-kms-signer.d.mts +62 -0
  8. package/dist/aws/aws-kms-signer.d.mts.map +1 -0
  9. package/dist/aws/aws-kms-signer.mjs +78 -0
  10. package/dist/aws/aws-kms-signer.mjs.map +1 -0
  11. package/dist/aws/aws4fetch.d.mts +62 -0
  12. package/dist/aws/aws4fetch.d.mts.map +1 -0
  13. package/dist/aws/aws4fetch.mjs +313 -0
  14. package/dist/aws/aws4fetch.mjs.map +1 -0
  15. package/dist/aws/index.d.mts +3 -0
  16. package/dist/aws/index.mjs +3 -0
  17. package/dist/gcp/gcp-kms-client.d.mts +70 -0
  18. package/dist/gcp/gcp-kms-client.d.mts.map +1 -0
  19. package/dist/gcp/gcp-kms-client.mjs +104 -0
  20. package/dist/gcp/gcp-kms-client.mjs.map +1 -0
  21. package/dist/gcp/index.d.mts +2 -0
  22. package/dist/gcp/index.mjs +3 -0
  23. package/dist/ledger/index.d.mts +73 -0
  24. package/dist/ledger/index.d.mts.map +1 -0
  25. package/dist/ledger/index.mjs +110 -0
  26. package/dist/ledger/index.mjs.map +1 -0
  27. package/dist/ledger/objects.d.mts +10 -0
  28. package/dist/ledger/objects.d.mts.map +1 -0
  29. package/dist/ledger/objects.mjs +16 -0
  30. package/dist/ledger/objects.mjs.map +1 -0
  31. package/dist/utils/utils.mjs +71 -0
  32. package/dist/utils/utils.mjs.map +1 -0
  33. package/dist/webcrypto/index.d.mts +32 -0
  34. package/dist/webcrypto/index.d.mts.map +1 -0
  35. package/dist/webcrypto/index.mjs +70 -0
  36. package/dist/webcrypto/index.mjs.map +1 -0
  37. package/package.json +35 -29
  38. package/src/aws/aws-kms-signer.ts +0 -9
  39. package/src/gcp/gcp-kms-client.ts +0 -9
  40. package/src/ledger/index.ts +4 -5
  41. package/src/ledger/objects.ts +10 -34
  42. package/src/utils/utils.ts +18 -10
  43. package/src/webcrypto/index.ts +6 -3
  44. package/aws/package.json +0 -6
  45. package/dist/cjs/aws/aws-client.d.ts +0 -43
  46. package/dist/cjs/aws/aws-client.js +0 -79
  47. package/dist/cjs/aws/aws-client.js.map +0 -7
  48. package/dist/cjs/aws/aws-kms-signer.d.ts +0 -61
  49. package/dist/cjs/aws/aws-kms-signer.js +0 -114
  50. package/dist/cjs/aws/aws-kms-signer.js.map +0 -7
  51. package/dist/cjs/aws/aws4fetch.d.ts +0 -125
  52. package/dist/cjs/aws/aws4fetch.js +0 -382
  53. package/dist/cjs/aws/aws4fetch.js.map +0 -7
  54. package/dist/cjs/aws/index.d.ts +0 -5
  55. package/dist/cjs/aws/index.js +0 -25
  56. package/dist/cjs/aws/index.js.map +0 -7
  57. package/dist/cjs/gcp/gcp-kms-client.d.ts +0 -68
  58. package/dist/cjs/gcp/gcp-kms-client.js +0 -147
  59. package/dist/cjs/gcp/gcp-kms-client.js.map +0 -7
  60. package/dist/cjs/gcp/index.d.ts +0 -4
  61. package/dist/cjs/gcp/index.js +0 -25
  62. package/dist/cjs/gcp/index.js.map +0 -7
  63. package/dist/cjs/ledger/bcs.d.ts +0 -14
  64. package/dist/cjs/ledger/bcs.js +0 -85
  65. package/dist/cjs/ledger/bcs.js.map +0 -7
  66. package/dist/cjs/ledger/index.d.ts +0 -66
  67. package/dist/cjs/ledger/index.js +0 -158
  68. package/dist/cjs/ledger/index.js.map +0 -7
  69. package/dist/cjs/ledger/objects.d.ts +0 -5
  70. package/dist/cjs/ledger/objects.js +0 -60
  71. package/dist/cjs/ledger/objects.js.map +0 -7
  72. package/dist/cjs/package.json +0 -5
  73. package/dist/cjs/utils/utils.d.ts +0 -18
  74. package/dist/cjs/utils/utils.js +0 -85
  75. package/dist/cjs/utils/utils.js.map +0 -7
  76. package/dist/cjs/webcrypto/index.d.ts +0 -26
  77. package/dist/cjs/webcrypto/index.js +0 -112
  78. package/dist/cjs/webcrypto/index.js.map +0 -7
  79. package/dist/esm/aws/aws-client.d.ts +0 -43
  80. package/dist/esm/aws/aws-client.js +0 -59
  81. package/dist/esm/aws/aws-client.js.map +0 -7
  82. package/dist/esm/aws/aws-kms-signer.d.ts +0 -61
  83. package/dist/esm/aws/aws-kms-signer.js +0 -94
  84. package/dist/esm/aws/aws-kms-signer.js.map +0 -7
  85. package/dist/esm/aws/aws4fetch.d.ts +0 -125
  86. package/dist/esm/aws/aws4fetch.js +0 -362
  87. package/dist/esm/aws/aws4fetch.js.map +0 -7
  88. package/dist/esm/aws/index.d.ts +0 -5
  89. package/dist/esm/aws/index.js +0 -5
  90. package/dist/esm/aws/index.js.map +0 -7
  91. package/dist/esm/gcp/gcp-kms-client.d.ts +0 -68
  92. package/dist/esm/gcp/gcp-kms-client.js +0 -127
  93. package/dist/esm/gcp/gcp-kms-client.js.map +0 -7
  94. package/dist/esm/gcp/index.d.ts +0 -4
  95. package/dist/esm/gcp/index.js +0 -5
  96. package/dist/esm/gcp/index.js.map +0 -7
  97. package/dist/esm/ledger/bcs.d.ts +0 -14
  98. package/dist/esm/ledger/bcs.js +0 -70
  99. package/dist/esm/ledger/bcs.js.map +0 -7
  100. package/dist/esm/ledger/index.d.ts +0 -66
  101. package/dist/esm/ledger/index.js +0 -138
  102. package/dist/esm/ledger/index.js.map +0 -7
  103. package/dist/esm/ledger/objects.d.ts +0 -5
  104. package/dist/esm/ledger/objects.js +0 -40
  105. package/dist/esm/ledger/objects.js.map +0 -7
  106. package/dist/esm/package.json +0 -5
  107. package/dist/esm/utils/utils.d.ts +0 -18
  108. package/dist/esm/utils/utils.js +0 -65
  109. package/dist/esm/utils/utils.js.map +0 -7
  110. package/dist/esm/webcrypto/index.d.ts +0 -26
  111. package/dist/esm/webcrypto/index.js +0 -92
  112. package/dist/esm/webcrypto/index.js.map +0 -7
  113. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  114. package/dist/tsconfig.tsbuildinfo +0 -1
  115. package/gcp/package.json +0 -6
  116. package/ledger/package.json +0 -6
  117. package/src/ledger/bcs.ts +0 -87
  118. package/webcrypto/package.json +0 -6
@@ -0,0 +1,70 @@
1
+ import { PublicKey, Signer } from "@haneullabs/haneul/cryptography";
2
+ import { KeyManagementServiceClient } from "@google-cloud/kms";
3
+
4
+ //#region src/gcp/gcp-kms-client.d.ts
5
+ /**
6
+ * Configuration options for initializing the GcpKmsSigner.
7
+ */
8
+ interface GcpKmsSignerOptions {
9
+ /** The version name generated from `client.cryptoKeyVersionPath()` */
10
+ versionName: string;
11
+ /** Options for setting up the GCP KMS client */
12
+ client: KeyManagementServiceClient;
13
+ /** Public key */
14
+ publicKey: PublicKey;
15
+ }
16
+ /**
17
+ * GCP KMS Signer integrates GCP Key Management Service (KMS) with the Haneul blockchain
18
+ * to provide signing capabilities using GCP-managed cryptographic keys.
19
+ */
20
+ declare class GcpKmsSigner extends Signer {
21
+ #private;
22
+ /**
23
+ * Creates an instance of GcpKmsSigner. It's expected to call the static `fromOptions`
24
+ * or `fromVersionName` method to create an instance.
25
+ * For example:
26
+ * ```
27
+ * const signer = await GcpKmsSigner.fromVersionName(versionName);
28
+ * ```
29
+ * @throws Will throw an error if required GCP credentials are not provided.
30
+ */
31
+ constructor({
32
+ versionName,
33
+ client,
34
+ publicKey
35
+ }: GcpKmsSignerOptions);
36
+ /**
37
+ * Retrieves the key scheme used by this signer.
38
+ * @returns GCP supports only `Secp256k1` and `Secp256r1` schemes.
39
+ */
40
+ getKeyScheme(): "ED25519" | "Secp256r1" | "Secp256k1" | "MultiSig" | "ZkLogin" | "Passkey";
41
+ /**
42
+ * Retrieves the public key associated with this signer.
43
+ * @returns The Secp256k1PublicKey instance.
44
+ * @throws Will throw an error if the public key has not been initialized.
45
+ */
46
+ getPublicKey(): PublicKey;
47
+ /**
48
+ * Signs the given data using GCP KMS.
49
+ * @param bytes - The data to be signed as a Uint8Array.
50
+ * @returns A promise that resolves to the signature as a Uint8Array.
51
+ * @throws Will throw an error if the public key is not initialized or if signing fails.
52
+ */
53
+ sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
54
+ /**
55
+ * Creates a GCP KMS signer from the provided options.
56
+ * Expects the credentials file to be set as an env variable
57
+ * (GOOGLE_APPLICATION_CREDENTIALS).
58
+ */
59
+ static fromOptions(options: {
60
+ projectId: string;
61
+ location: string;
62
+ keyRing: string;
63
+ cryptoKey: string;
64
+ cryptoKeyVersion: string;
65
+ }): Promise<GcpKmsSigner>;
66
+ static fromVersionName(versionName: string): Promise<GcpKmsSigner>;
67
+ }
68
+ //#endregion
69
+ export { GcpKmsSigner, GcpKmsSignerOptions };
70
+ //# sourceMappingURL=gcp-kms-client.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gcp-kms-client.d.mts","names":[],"sources":["../../src/gcp/gcp-kms-client.ts"],"mappings":";;;;;AAcA;;UAAiB,mBAAA;EAMI;EAJpB,WAAA;EAEA;EAAA,MAAA,EAAQ,0BAAA;EAER;EAAA,SAAA,EAAW,SAAA;AAAA;;AAOZ;;;cAAa,YAAA,SAAqB,MAAA;EAAA;EAgBE;;;;;;;;;;IAArB,WAAA;IAAa,MAAA;IAAQ;EAAA,GAAa,mBAAA;EA0EA;;;;EA7DhD,YAAA,CAAA;;;;;;EASA,YAAA,CAAA,GAAY,SAAA;EAtBuB;;;;;;EAgC7B,IAAA,CAAK,KAAA,EAAO,UAAA,GAAa,OAAA,CAAQ,UAAA,CAAW,WAAA;EAAhC;;;;;EAAA,OAkBL,WAAA,CAAY,OAAA;IACxB,SAAA;IACA,QAAA;IACA,OAAA;IACA,SAAA;IACA,gBAAA;EAAA,IACA,OAAA,CAAA,YAAA;EAAA,OAkBY,eAAA,CAAgB,WAAA,WAAmB,OAAA,CAAA,YAAA;AAAA"}
@@ -0,0 +1,104 @@
1
+ import { getConcatenatedSignature, publicKeyFromDER } from "../utils/utils.mjs";
2
+ import { SIGNATURE_FLAG_TO_SCHEME, Signer } from "@haneullabs/haneul/cryptography";
3
+ import { fromBase64 } from "@haneullabs/haneul/utils";
4
+ import { Secp256k1PublicKey } from "@haneullabs/haneul/keypairs/secp256k1";
5
+ import { Secp256r1PublicKey } from "@haneullabs/haneul/keypairs/secp256r1";
6
+ import { KeyManagementServiceClient } from "@google-cloud/kms";
7
+
8
+ //#region src/gcp/gcp-kms-client.ts
9
+ /**
10
+ * GCP KMS Signer integrates GCP Key Management Service (KMS) with the Haneul blockchain
11
+ * to provide signing capabilities using GCP-managed cryptographic keys.
12
+ */
13
+ var GcpKmsSigner = class GcpKmsSigner extends Signer {
14
+ #publicKey;
15
+ /** GCP KMS client instance */
16
+ #client;
17
+ /** GCP KMS version name (generated from `client.cryptoKeyVersionPath()`) */
18
+ #versionName;
19
+ /**
20
+ * Creates an instance of GcpKmsSigner. It's expected to call the static `fromOptions`
21
+ * or `fromVersionName` method to create an instance.
22
+ * For example:
23
+ * ```
24
+ * const signer = await GcpKmsSigner.fromVersionName(versionName);
25
+ * ```
26
+ * @throws Will throw an error if required GCP credentials are not provided.
27
+ */
28
+ constructor({ versionName, client, publicKey }) {
29
+ super();
30
+ if (!versionName) throw new Error("Version name is required");
31
+ this.#client = client;
32
+ this.#versionName = versionName;
33
+ this.#publicKey = publicKey;
34
+ }
35
+ /**
36
+ * Retrieves the key scheme used by this signer.
37
+ * @returns GCP supports only `Secp256k1` and `Secp256r1` schemes.
38
+ */
39
+ getKeyScheme() {
40
+ return SIGNATURE_FLAG_TO_SCHEME[this.#publicKey.flag()];
41
+ }
42
+ /**
43
+ * Retrieves the public key associated with this signer.
44
+ * @returns The Secp256k1PublicKey instance.
45
+ * @throws Will throw an error if the public key has not been initialized.
46
+ */
47
+ getPublicKey() {
48
+ return this.#publicKey;
49
+ }
50
+ /**
51
+ * Signs the given data using GCP KMS.
52
+ * @param bytes - The data to be signed as a Uint8Array.
53
+ * @returns A promise that resolves to the signature as a Uint8Array.
54
+ * @throws Will throw an error if the public key is not initialized or if signing fails.
55
+ */
56
+ async sign(bytes) {
57
+ const [signResponse] = await this.#client.asymmetricSign({
58
+ name: this.#versionName,
59
+ data: bytes
60
+ });
61
+ if (!signResponse.signature) throw new Error("No signature returned from GCP KMS");
62
+ return getConcatenatedSignature(signResponse.signature, this.getKeyScheme());
63
+ }
64
+ /**
65
+ * Creates a GCP KMS signer from the provided options.
66
+ * Expects the credentials file to be set as an env variable
67
+ * (GOOGLE_APPLICATION_CREDENTIALS).
68
+ */
69
+ static async fromOptions(options) {
70
+ const client = new KeyManagementServiceClient();
71
+ const versionName = client.cryptoKeyVersionPath(options.projectId, options.location, options.keyRing, options.cryptoKey, options.cryptoKeyVersion);
72
+ return new GcpKmsSigner({
73
+ versionName,
74
+ client,
75
+ publicKey: await getPublicKey(client, versionName)
76
+ });
77
+ }
78
+ static async fromVersionName(versionName) {
79
+ const client = new KeyManagementServiceClient();
80
+ return new GcpKmsSigner({
81
+ versionName,
82
+ client,
83
+ publicKey: await getPublicKey(client, versionName)
84
+ });
85
+ }
86
+ };
87
+ /**
88
+ * Retrieves the public key associated with the given version name.
89
+ */
90
+ async function getPublicKey(client, versionName) {
91
+ const [publicKey] = await client.getPublicKey({ name: versionName });
92
+ const { algorithm, pem } = publicKey;
93
+ if (!pem) throw new Error("No PEM key returned from GCP KMS");
94
+ const compressedKey = publicKeyFromDER(fromBase64(pem.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").replace(/\s/g, "")));
95
+ switch (algorithm) {
96
+ case "EC_SIGN_SECP256K1_SHA256": return new Secp256k1PublicKey(compressedKey);
97
+ case "EC_SIGN_P256_SHA256": return new Secp256r1PublicKey(compressedKey);
98
+ default: throw new Error(`Unsupported algorithm: ${algorithm}`);
99
+ }
100
+ }
101
+
102
+ //#endregion
103
+ export { GcpKmsSigner };
104
+ //# sourceMappingURL=gcp-kms-client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gcp-kms-client.mjs","names":["#client","#versionName","#publicKey"],"sources":["../../src/gcp/gcp-kms-client.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { KeyManagementServiceClient } from '@google-cloud/kms';\nimport type { PublicKey, SignatureFlag } from '@haneullabs/haneul/cryptography';\nimport { SIGNATURE_FLAG_TO_SCHEME, Signer } from '@haneullabs/haneul/cryptography';\nimport { Secp256k1PublicKey } from '@haneullabs/haneul/keypairs/secp256k1';\nimport { Secp256r1PublicKey } from '@haneullabs/haneul/keypairs/secp256r1';\nimport { fromBase64 } from '@haneullabs/haneul/utils';\n\nimport { getConcatenatedSignature, publicKeyFromDER } from '../utils/utils.js';\n\n/**\n * Configuration options for initializing the GcpKmsSigner.\n */\nexport interface GcpKmsSignerOptions {\n\t/** The version name generated from `client.cryptoKeyVersionPath()` */\n\tversionName: string;\n\t/** Options for setting up the GCP KMS client */\n\tclient: KeyManagementServiceClient;\n\t/** Public key */\n\tpublicKey: PublicKey;\n}\n\n/**\n * GCP KMS Signer integrates GCP Key Management Service (KMS) with the Haneul blockchain\n * to provide signing capabilities using GCP-managed cryptographic keys.\n */\nexport class GcpKmsSigner extends Signer {\n\t#publicKey: PublicKey;\n\t/** GCP KMS client instance */\n\t#client: KeyManagementServiceClient;\n\t/** GCP KMS version name (generated from `client.cryptoKeyVersionPath()`) */\n\t#versionName: string;\n\n\t/**\n\t * Creates an instance of GcpKmsSigner. It's expected to call the static `fromOptions`\n\t * or `fromVersionName` method to create an instance.\n\t * For example:\n\t * ```\n\t * const signer = await GcpKmsSigner.fromVersionName(versionName);\n\t * ```\n\t * @throws Will throw an error if required GCP credentials are not provided.\n\t */\n\tconstructor({ versionName, client, publicKey }: GcpKmsSignerOptions) {\n\t\tsuper();\n\t\tif (!versionName) throw new Error('Version name is required');\n\n\t\tthis.#client = client;\n\t\tthis.#versionName = versionName;\n\t\tthis.#publicKey = publicKey;\n\t}\n\n\t/**\n\t * Retrieves the key scheme used by this signer.\n\t * @returns GCP supports only `Secp256k1` and `Secp256r1` schemes.\n\t */\n\tgetKeyScheme() {\n\t\treturn SIGNATURE_FLAG_TO_SCHEME[this.#publicKey.flag() as SignatureFlag];\n\t}\n\n\t/**\n\t * Retrieves the public key associated with this signer.\n\t * @returns The Secp256k1PublicKey instance.\n\t * @throws Will throw an error if the public key has not been initialized.\n\t */\n\tgetPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n\n\t/**\n\t * Signs the given data using GCP KMS.\n\t * @param bytes - The data to be signed as a Uint8Array.\n\t * @returns A promise that resolves to the signature as a Uint8Array.\n\t * @throws Will throw an error if the public key is not initialized or if signing fails.\n\t */\n\tasync sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>> {\n\t\tconst [signResponse] = await this.#client.asymmetricSign({\n\t\t\tname: this.#versionName,\n\t\t\tdata: bytes,\n\t\t});\n\n\t\tif (!signResponse.signature) {\n\t\t\tthrow new Error('No signature returned from GCP KMS');\n\t\t}\n\n\t\treturn getConcatenatedSignature(signResponse.signature as Uint8Array, this.getKeyScheme());\n\t}\n\n\t/**\n\t * Creates a GCP KMS signer from the provided options.\n\t * Expects the credentials file to be set as an env variable\n\t * (GOOGLE_APPLICATION_CREDENTIALS).\n\t */\n\tstatic async fromOptions(options: {\n\t\tprojectId: string;\n\t\tlocation: string;\n\t\tkeyRing: string;\n\t\tcryptoKey: string;\n\t\tcryptoKeyVersion: string;\n\t}) {\n\t\tconst client = new KeyManagementServiceClient();\n\n\t\tconst versionName = client.cryptoKeyVersionPath(\n\t\t\toptions.projectId,\n\t\t\toptions.location,\n\t\t\toptions.keyRing,\n\t\t\toptions.cryptoKey,\n\t\t\toptions.cryptoKeyVersion,\n\t\t);\n\n\t\treturn new GcpKmsSigner({\n\t\t\tversionName,\n\t\t\tclient,\n\t\t\tpublicKey: await getPublicKey(client, versionName),\n\t\t});\n\t}\n\n\tstatic async fromVersionName(versionName: string) {\n\t\tconst client = new KeyManagementServiceClient();\n\t\treturn new GcpKmsSigner({\n\t\t\tversionName,\n\t\t\tclient,\n\t\t\tpublicKey: await getPublicKey(client, versionName),\n\t\t});\n\t}\n}\n\n/**\n * Retrieves the public key associated with the given version name.\n */\nasync function getPublicKey(\n\tclient: KeyManagementServiceClient,\n\tversionName: string,\n): Promise<PublicKey> {\n\tconst [publicKey] = await client.getPublicKey({ name: versionName });\n\n\tconst { algorithm, pem } = publicKey;\n\n\tif (!pem) throw new Error('No PEM key returned from GCP KMS');\n\n\tconst base64 = pem\n\t\t.replace('-----BEGIN PUBLIC KEY-----', '')\n\t\t.replace('-----END PUBLIC KEY-----', '')\n\t\t.replace(/\\s/g, '');\n\n\tconst compressedKey = publicKeyFromDER(fromBase64(base64));\n\n\tswitch (algorithm) {\n\t\tcase 'EC_SIGN_SECP256K1_SHA256':\n\t\t\treturn new Secp256k1PublicKey(compressedKey);\n\t\tcase 'EC_SIGN_P256_SHA256':\n\t\t\treturn new Secp256r1PublicKey(compressedKey);\n\t\tdefault:\n\t\t\tthrow new Error(`Unsupported algorithm: ${algorithm}`);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AA2BA,IAAa,eAAb,MAAa,qBAAqB,OAAO;CACxC;;CAEA;;CAEA;;;;;;;;;;CAWA,YAAY,EAAE,aAAa,QAAQ,aAAkC;AACpE,SAAO;AACP,MAAI,CAAC,YAAa,OAAM,IAAI,MAAM,2BAA2B;AAE7D,QAAKA,SAAU;AACf,QAAKC,cAAe;AACpB,QAAKC,YAAa;;;;;;CAOnB,eAAe;AACd,SAAO,yBAAyB,MAAKA,UAAW,MAAM;;;;;;;CAQvD,eAAe;AACd,SAAO,MAAKA;;;;;;;;CASb,MAAM,KAAK,OAAqD;EAC/D,MAAM,CAAC,gBAAgB,MAAM,MAAKF,OAAQ,eAAe;GACxD,MAAM,MAAKC;GACX,MAAM;GACN,CAAC;AAEF,MAAI,CAAC,aAAa,UACjB,OAAM,IAAI,MAAM,qCAAqC;AAGtD,SAAO,yBAAyB,aAAa,WAAyB,KAAK,cAAc,CAAC;;;;;;;CAQ3F,aAAa,YAAY,SAMtB;EACF,MAAM,SAAS,IAAI,4BAA4B;EAE/C,MAAM,cAAc,OAAO,qBAC1B,QAAQ,WACR,QAAQ,UACR,QAAQ,SACR,QAAQ,WACR,QAAQ,iBACR;AAED,SAAO,IAAI,aAAa;GACvB;GACA;GACA,WAAW,MAAM,aAAa,QAAQ,YAAY;GAClD,CAAC;;CAGH,aAAa,gBAAgB,aAAqB;EACjD,MAAM,SAAS,IAAI,4BAA4B;AAC/C,SAAO,IAAI,aAAa;GACvB;GACA;GACA,WAAW,MAAM,aAAa,QAAQ,YAAY;GAClD,CAAC;;;;;;AAOJ,eAAe,aACd,QACA,aACqB;CACrB,MAAM,CAAC,aAAa,MAAM,OAAO,aAAa,EAAE,MAAM,aAAa,CAAC;CAEpE,MAAM,EAAE,WAAW,QAAQ;AAE3B,KAAI,CAAC,IAAK,OAAM,IAAI,MAAM,mCAAmC;CAO7D,MAAM,gBAAgB,iBAAiB,WALxB,IACb,QAAQ,8BAA8B,GAAG,CACzC,QAAQ,4BAA4B,GAAG,CACvC,QAAQ,OAAO,GAAG,CAEqC,CAAC;AAE1D,SAAQ,WAAR;EACC,KAAK,2BACJ,QAAO,IAAI,mBAAmB,cAAc;EAC7C,KAAK,sBACJ,QAAO,IAAI,mBAAmB,cAAc;EAC7C,QACC,OAAM,IAAI,MAAM,0BAA0B,YAAY"}
@@ -0,0 +1,2 @@
1
+ import { GcpKmsSigner, GcpKmsSignerOptions } from "./gcp-kms-client.mjs";
2
+ export { GcpKmsSigner, type GcpKmsSignerOptions };
@@ -0,0 +1,3 @@
1
+ import { GcpKmsSigner } from "./gcp-kms-client.mjs";
2
+
3
+ export { GcpKmsSigner };
@@ -0,0 +1,73 @@
1
+ import { getInputObjects } from "./objects.mjs";
2
+ import { SignatureWithBytes, Signer } from "@haneullabs/haneul/cryptography";
3
+ import { Ed25519PublicKey } from "@haneullabs/haneul/keypairs/ed25519";
4
+ import HaneulLedgerClient, { Resolution } from "@haneullabs/ledgerjs-hw-app-haneul";
5
+ import { ClientWithCoreApi } from "@haneullabs/haneul/client";
6
+
7
+ //#region src/ledger/index.d.ts
8
+ /**
9
+ * Configuration options for initializing the LedgerSigner.
10
+ */
11
+ interface LedgerSignerOptions {
12
+ publicKey: Ed25519PublicKey;
13
+ derivationPath: string;
14
+ ledgerClient: HaneulLedgerClient;
15
+ haneulClient: ClientWithCoreApi;
16
+ }
17
+ /**
18
+ * Ledger integrates with the Haneul blockchain to provide signing capabilities using Ledger devices.
19
+ */
20
+ declare class LedgerSigner extends Signer {
21
+ #private;
22
+ /**
23
+ * Creates an instance of LedgerSigner. It's expected to call the static `fromDerivationPath` method to create an instance.
24
+ * @example
25
+ * ```
26
+ * const signer = await LedgerSigner.fromDerivationPath(derivationPath, options);
27
+ * ```
28
+ */
29
+ constructor({
30
+ publicKey,
31
+ derivationPath,
32
+ ledgerClient,
33
+ haneulClient
34
+ }: LedgerSignerOptions);
35
+ /**
36
+ * Retrieves the key scheme used by this signer.
37
+ */
38
+ getKeyScheme(): "ED25519";
39
+ /**
40
+ * Retrieves the public key associated with this signer.
41
+ * @returns The Ed25519PublicKey instance.
42
+ */
43
+ getPublicKey(): Ed25519PublicKey;
44
+ /**
45
+ * Signs the provided transaction bytes.
46
+ * @returns The signed transaction bytes and signature.
47
+ */
48
+ signTransaction(bytes: Uint8Array, bcsObjects?: Uint8Array[], resolution?: Resolution): Promise<SignatureWithBytes>;
49
+ /**
50
+ * Signs the provided personal message.
51
+ * @returns The signed message bytes and signature.
52
+ */
53
+ signPersonalMessage(bytes: Uint8Array): Promise<SignatureWithBytes>;
54
+ /**
55
+ * Prepares the signer by fetching and setting the public key from a Ledger device.
56
+ * It is recommended to initialize an `LedgerSigner` instance using this function.
57
+ * @returns A promise that resolves once a `LedgerSigner` instance is prepared (public key is set).
58
+ */
59
+ static fromDerivationPath(derivationPath: string, ledgerClient: HaneulLedgerClient, haneulClient: ClientWithCoreApi): Promise<LedgerSigner>;
60
+ /**
61
+ * Generic signing is not supported by Ledger.
62
+ * @throws Always throws an error indicating generic signing is unsupported.
63
+ */
64
+ sign(): never;
65
+ /**
66
+ * Generic signing is not supported by Ledger.
67
+ * @throws Always throws an error indicating generic signing is unsupported.
68
+ */
69
+ signWithIntent(): never;
70
+ }
71
+ //#endregion
72
+ export { LedgerSigner, LedgerSignerOptions, getInputObjects };
73
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/ledger/index.ts"],"mappings":";;;;;;;AAoBA;;;AAAA,UAAiB,mBAAA;EAChB,SAAA,EAAW,gBAAA;EACX,cAAA;EACA,YAAA,EAAc,kBAAA;EACd,YAAA,EAAc,iBAAA;AAAA;;;;cAMF,YAAA,SAAqB,MAAA;EAAA;EANnB;;;AAMf;;;;;IAae,SAAA;IAAW,cAAA;IAAgB,YAAA;IAAc;EAAA,GAAgB,mBAAA;EAA9B;;;EAWhC,YAAA,CAAA;EAiBD;;;;EATC,YAAA,CAAA,GAAY,gBAAA;EA0CqB;;;;EAlC3B,eAAA,CACd,KAAA,EAAO,UAAA,EACP,UAAA,GAAa,UAAA,IACb,UAAA,GAAa,UAAA,GACX,OAAA,CAAQ,kBAAA;EA0DqB;;;;EA5BjB,mBAAA,CAAoB,KAAA,EAAO,UAAA,GAAa,OAAA,CAAQ,kBAAA;EA1E9B;;;;;EAAA,OAmGpB,kBAAA,CACZ,cAAA,UACA,YAAA,EAAc,kBAAA,EACd,YAAA,EAAc,iBAAA,GAAiB,OAAA,CAAA,YAAA;EAzFP;;;;EA4GhB,IAAA,CAAA;EA5G8D;;;;EAoH9D,cAAA,CAAA;AAAA"}
@@ -0,0 +1,110 @@
1
+ import { getInputObjects } from "./objects.mjs";
2
+ import { Signer, messageWithIntent, toSerializedSignature } from "@haneullabs/haneul/cryptography";
3
+ import { toBase64 } from "@haneullabs/haneul/utils";
4
+ import { Ed25519PublicKey } from "@haneullabs/haneul/keypairs/ed25519";
5
+ import { Transaction } from "@haneullabs/haneul/transactions";
6
+ import { bcs } from "@haneullabs/haneul/bcs";
7
+
8
+ //#region src/ledger/index.ts
9
+ /**
10
+ * Ledger integrates with the Haneul blockchain to provide signing capabilities using Ledger devices.
11
+ */
12
+ var LedgerSigner = class LedgerSigner extends Signer {
13
+ #derivationPath;
14
+ #publicKey;
15
+ #ledgerClient;
16
+ #haneulClient;
17
+ /**
18
+ * Creates an instance of LedgerSigner. It's expected to call the static `fromDerivationPath` method to create an instance.
19
+ * @example
20
+ * ```
21
+ * const signer = await LedgerSigner.fromDerivationPath(derivationPath, options);
22
+ * ```
23
+ */
24
+ constructor({ publicKey, derivationPath, ledgerClient, haneulClient }) {
25
+ super();
26
+ this.#publicKey = publicKey;
27
+ this.#derivationPath = derivationPath;
28
+ this.#ledgerClient = ledgerClient;
29
+ this.#haneulClient = haneulClient;
30
+ }
31
+ /**
32
+ * Retrieves the key scheme used by this signer.
33
+ */
34
+ getKeyScheme() {
35
+ return "ED25519";
36
+ }
37
+ /**
38
+ * Retrieves the public key associated with this signer.
39
+ * @returns The Ed25519PublicKey instance.
40
+ */
41
+ getPublicKey() {
42
+ return this.#publicKey;
43
+ }
44
+ /**
45
+ * Signs the provided transaction bytes.
46
+ * @returns The signed transaction bytes and signature.
47
+ */
48
+ async signTransaction(bytes, bcsObjects, resolution) {
49
+ const transactionOptions = bcsObjects ? { bcsObjects } : await getInputObjects(Transaction.from(bytes), this.#haneulClient).catch(() => ({ bcsObjects: [] }));
50
+ const intentMessage = messageWithIntent("TransactionData", bytes);
51
+ const { signature } = await this.#ledgerClient.signTransaction(this.#derivationPath, intentMessage, transactionOptions, resolution);
52
+ return {
53
+ bytes: toBase64(bytes),
54
+ signature: toSerializedSignature({
55
+ signature,
56
+ signatureScheme: this.getKeyScheme(),
57
+ publicKey: this.#publicKey
58
+ })
59
+ };
60
+ }
61
+ /**
62
+ * Signs the provided personal message.
63
+ * @returns The signed message bytes and signature.
64
+ */
65
+ async signPersonalMessage(bytes) {
66
+ const intentMessage = messageWithIntent("PersonalMessage", bcs.byteVector().serialize(bytes).toBytes());
67
+ const { signature } = await this.#ledgerClient.signTransaction(this.#derivationPath, intentMessage);
68
+ return {
69
+ bytes: toBase64(bytes),
70
+ signature: toSerializedSignature({
71
+ signature,
72
+ signatureScheme: this.getKeyScheme(),
73
+ publicKey: this.#publicKey
74
+ })
75
+ };
76
+ }
77
+ /**
78
+ * Prepares the signer by fetching and setting the public key from a Ledger device.
79
+ * It is recommended to initialize an `LedgerSigner` instance using this function.
80
+ * @returns A promise that resolves once a `LedgerSigner` instance is prepared (public key is set).
81
+ */
82
+ static async fromDerivationPath(derivationPath, ledgerClient, haneulClient) {
83
+ const { publicKey } = await ledgerClient.getPublicKey(derivationPath);
84
+ if (!publicKey) throw new Error("Failed to get public key from Ledger.");
85
+ return new LedgerSigner({
86
+ derivationPath,
87
+ publicKey: new Ed25519PublicKey(publicKey),
88
+ ledgerClient,
89
+ haneulClient
90
+ });
91
+ }
92
+ /**
93
+ * Generic signing is not supported by Ledger.
94
+ * @throws Always throws an error indicating generic signing is unsupported.
95
+ */
96
+ sign() {
97
+ throw new Error("Ledger Signer does not support generic signing.");
98
+ }
99
+ /**
100
+ * Generic signing is not supported by Ledger.
101
+ * @throws Always throws an error indicating generic signing is unsupported.
102
+ */
103
+ signWithIntent() {
104
+ throw new Error("Ledger Signer does not support generic signing.");
105
+ }
106
+ };
107
+
108
+ //#endregion
109
+ export { LedgerSigner, getInputObjects };
110
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["#publicKey","#derivationPath","#ledgerClient","#haneulClient"],"sources":["../../src/ledger/index.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type HaneulLedgerClient from '@haneullabs/ledgerjs-hw-app-haneul';\nimport type { ClientWithCoreApi } from '@haneullabs/haneul/client';\nimport type { SignatureWithBytes } from '@haneullabs/haneul/cryptography';\nimport { messageWithIntent, Signer, toSerializedSignature } from '@haneullabs/haneul/cryptography';\nimport { Ed25519PublicKey } from '@haneullabs/haneul/keypairs/ed25519';\nimport { Transaction } from '@haneullabs/haneul/transactions';\nimport { toBase64 } from '@haneullabs/haneul/utils';\n\nimport { bcs } from '@haneullabs/haneul/bcs';\nimport { getInputObjects } from './objects.js';\nimport type { Resolution } from '@haneullabs/ledgerjs-hw-app-haneul';\n\nexport { getInputObjects } from './objects.js';\n\n/**\n * Configuration options for initializing the LedgerSigner.\n */\nexport interface LedgerSignerOptions {\n\tpublicKey: Ed25519PublicKey;\n\tderivationPath: string;\n\tledgerClient: HaneulLedgerClient;\n\thaneulClient: ClientWithCoreApi;\n}\n\n/**\n * Ledger integrates with the Haneul blockchain to provide signing capabilities using Ledger devices.\n */\nexport class LedgerSigner extends Signer {\n\t#derivationPath: string;\n\t#publicKey: Ed25519PublicKey;\n\t#ledgerClient: HaneulLedgerClient;\n\t#haneulClient: ClientWithCoreApi;\n\n\t/**\n\t * Creates an instance of LedgerSigner. It's expected to call the static `fromDerivationPath` method to create an instance.\n\t * @example\n\t * ```\n\t * const signer = await LedgerSigner.fromDerivationPath(derivationPath, options);\n\t * ```\n\t */\n\tconstructor({ publicKey, derivationPath, ledgerClient, haneulClient }: LedgerSignerOptions) {\n\t\tsuper();\n\t\tthis.#publicKey = publicKey;\n\t\tthis.#derivationPath = derivationPath;\n\t\tthis.#ledgerClient = ledgerClient;\n\t\tthis.#haneulClient = haneulClient;\n\t}\n\n\t/**\n\t * Retrieves the key scheme used by this signer.\n\t */\n\toverride getKeyScheme() {\n\t\treturn 'ED25519' as const;\n\t}\n\n\t/**\n\t * Retrieves the public key associated with this signer.\n\t * @returns The Ed25519PublicKey instance.\n\t */\n\toverride getPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n\n\t/**\n\t * Signs the provided transaction bytes.\n\t * @returns The signed transaction bytes and signature.\n\t */\n\toverride async signTransaction(\n\t\tbytes: Uint8Array,\n\t\tbcsObjects?: Uint8Array[],\n\t\tresolution?: Resolution,\n\t): Promise<SignatureWithBytes> {\n\t\tconst transactionOptions = bcsObjects\n\t\t\t? { bcsObjects }\n\t\t\t: await getInputObjects(Transaction.from(bytes), this.#haneulClient).catch(() => ({\n\t\t\t\t\t// Fail gracefully so network errors or serialization issues don't break transaction signing:\n\t\t\t\t\tbcsObjects: [],\n\t\t\t\t}));\n\n\t\tconst intentMessage = messageWithIntent('TransactionData', bytes);\n\t\tconst { signature } = await this.#ledgerClient.signTransaction(\n\t\t\tthis.#derivationPath,\n\t\t\tintentMessage,\n\t\t\ttransactionOptions,\n\t\t\tresolution,\n\t\t);\n\n\t\treturn {\n\t\t\tbytes: toBase64(bytes),\n\t\t\tsignature: toSerializedSignature({\n\t\t\t\tsignature,\n\t\t\t\tsignatureScheme: this.getKeyScheme(),\n\t\t\t\tpublicKey: this.#publicKey,\n\t\t\t}),\n\t\t};\n\t}\n\n\t/**\n\t * Signs the provided personal message.\n\t * @returns The signed message bytes and signature.\n\t */\n\toverride async signPersonalMessage(bytes: Uint8Array): Promise<SignatureWithBytes> {\n\t\tconst intentMessage = messageWithIntent(\n\t\t\t'PersonalMessage',\n\t\t\tbcs.byteVector().serialize(bytes).toBytes(),\n\t\t);\n\t\tconst { signature } = await this.#ledgerClient.signTransaction(\n\t\t\tthis.#derivationPath,\n\t\t\tintentMessage,\n\t\t);\n\n\t\treturn {\n\t\t\tbytes: toBase64(bytes),\n\t\t\tsignature: toSerializedSignature({\n\t\t\t\tsignature,\n\t\t\t\tsignatureScheme: this.getKeyScheme(),\n\t\t\t\tpublicKey: this.#publicKey,\n\t\t\t}),\n\t\t};\n\t}\n\n\t/**\n\t * Prepares the signer by fetching and setting the public key from a Ledger device.\n\t * It is recommended to initialize an `LedgerSigner` instance using this function.\n\t * @returns A promise that resolves once a `LedgerSigner` instance is prepared (public key is set).\n\t */\n\tstatic async fromDerivationPath(\n\t\tderivationPath: string,\n\t\tledgerClient: HaneulLedgerClient,\n\t\thaneulClient: ClientWithCoreApi,\n\t) {\n\t\tconst { publicKey } = await ledgerClient.getPublicKey(derivationPath);\n\t\tif (!publicKey) {\n\t\t\tthrow new Error('Failed to get public key from Ledger.');\n\t\t}\n\n\t\treturn new LedgerSigner({\n\t\t\tderivationPath,\n\t\t\tpublicKey: new Ed25519PublicKey(publicKey),\n\t\t\tledgerClient,\n\t\t\thaneulClient,\n\t\t});\n\t}\n\n\t/**\n\t * Generic signing is not supported by Ledger.\n\t * @throws Always throws an error indicating generic signing is unsupported.\n\t */\n\toverride sign(): never {\n\t\tthrow new Error('Ledger Signer does not support generic signing.');\n\t}\n\n\t/**\n\t * Generic signing is not supported by Ledger.\n\t * @throws Always throws an error indicating generic signing is unsupported.\n\t */\n\toverride signWithIntent(): never {\n\t\tthrow new Error('Ledger Signer does not support generic signing.');\n\t}\n}\n"],"mappings":";;;;;;;;;;;AA8BA,IAAa,eAAb,MAAa,qBAAqB,OAAO;CACxC;CACA;CACA;CACA;;;;;;;;CASA,YAAY,EAAE,WAAW,gBAAgB,cAAc,gBAAqC;AAC3F,SAAO;AACP,QAAKA,YAAa;AAClB,QAAKC,iBAAkB;AACvB,QAAKC,eAAgB;AACrB,QAAKC,eAAgB;;;;;CAMtB,AAAS,eAAe;AACvB,SAAO;;;;;;CAOR,AAAS,eAAe;AACvB,SAAO,MAAKH;;;;;;CAOb,MAAe,gBACd,OACA,YACA,YAC8B;EAC9B,MAAM,qBAAqB,aACxB,EAAE,YAAY,GACd,MAAM,gBAAgB,YAAY,KAAK,MAAM,EAAE,MAAKG,aAAc,CAAC,aAAa,EAEhF,YAAY,EAAE,EACd,EAAE;EAEL,MAAM,gBAAgB,kBAAkB,mBAAmB,MAAM;EACjE,MAAM,EAAE,cAAc,MAAM,MAAKD,aAAc,gBAC9C,MAAKD,gBACL,eACA,oBACA,WACA;AAED,SAAO;GACN,OAAO,SAAS,MAAM;GACtB,WAAW,sBAAsB;IAChC;IACA,iBAAiB,KAAK,cAAc;IACpC,WAAW,MAAKD;IAChB,CAAC;GACF;;;;;;CAOF,MAAe,oBAAoB,OAAgD;EAClF,MAAM,gBAAgB,kBACrB,mBACA,IAAI,YAAY,CAAC,UAAU,MAAM,CAAC,SAAS,CAC3C;EACD,MAAM,EAAE,cAAc,MAAM,MAAKE,aAAc,gBAC9C,MAAKD,gBACL,cACA;AAED,SAAO;GACN,OAAO,SAAS,MAAM;GACtB,WAAW,sBAAsB;IAChC;IACA,iBAAiB,KAAK,cAAc;IACpC,WAAW,MAAKD;IAChB,CAAC;GACF;;;;;;;CAQF,aAAa,mBACZ,gBACA,cACA,cACC;EACD,MAAM,EAAE,cAAc,MAAM,aAAa,aAAa,eAAe;AACrE,MAAI,CAAC,UACJ,OAAM,IAAI,MAAM,wCAAwC;AAGzD,SAAO,IAAI,aAAa;GACvB;GACA,WAAW,IAAI,iBAAiB,UAAU;GAC1C;GACA;GACA,CAAC;;;;;;CAOH,AAAS,OAAc;AACtB,QAAM,IAAI,MAAM,kDAAkD;;;;;;CAOnE,AAAS,iBAAwB;AAChC,QAAM,IAAI,MAAM,kDAAkD"}
@@ -0,0 +1,10 @@
1
+ import { Transaction } from "@haneullabs/haneul/transactions";
2
+ import { ClientWithCoreApi } from "@haneullabs/haneul/client";
3
+
4
+ //#region src/ledger/objects.d.ts
5
+ declare const getInputObjects: (transaction: Transaction, client: ClientWithCoreApi) => Promise<{
6
+ bcsObjects: Uint8Array<ArrayBuffer>[];
7
+ }>;
8
+ //#endregion
9
+ export { getInputObjects };
10
+ //# sourceMappingURL=objects.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objects.d.mts","names":[],"sources":["../../src/ledger/objects.ts"],"mappings":";;;;cAMa,eAAA,GAAyB,WAAA,EAAa,WAAA,EAAa,MAAA,EAAQ,iBAAA,KAAiB,OAAA"}
@@ -0,0 +1,16 @@
1
+ //#region src/ledger/objects.ts
2
+ const getInputObjects = async (transaction, client) => {
3
+ const data = transaction.getData();
4
+ const gasObjectIds = data.gasData.payment?.map((object) => object.objectId) ?? [];
5
+ const inputObjectIds = data.inputs.map((input) => {
6
+ return input.$kind === "Object" && input.Object.$kind === "ImmOrOwnedObject" ? input.Object.ImmOrOwnedObject.objectId : null;
7
+ }).filter((objectId) => !!objectId);
8
+ return { bcsObjects: (await client.core.getObjects({
9
+ objectIds: [...gasObjectIds, ...inputObjectIds],
10
+ include: { objectBcs: true }
11
+ })).objects.filter((obj) => !(obj instanceof Error)).map((object) => object.objectBcs).filter((bytes) => !!bytes) };
12
+ };
13
+
14
+ //#endregion
15
+ export { getInputObjects };
16
+ //# sourceMappingURL=objects.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objects.mjs","names":[],"sources":["../../src/ledger/objects.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction } from '@haneullabs/haneul/transactions';\nimport type { ClientWithCoreApi } from '@haneullabs/haneul/client';\n\nexport const getInputObjects = async (transaction: Transaction, client: ClientWithCoreApi) => {\n\tconst data = transaction.getData();\n\n\tconst gasObjectIds = data.gasData.payment?.map((object) => object.objectId) ?? [];\n\tconst inputObjectIds = data.inputs\n\t\t.map((input) => {\n\t\t\treturn input.$kind === 'Object' && input.Object.$kind === 'ImmOrOwnedObject'\n\t\t\t\t? input.Object.ImmOrOwnedObject.objectId\n\t\t\t\t: null;\n\t\t})\n\t\t.filter((objectId): objectId is string => !!objectId);\n\n\tconst response = await client.core.getObjects({\n\t\tobjectIds: [...gasObjectIds, ...inputObjectIds],\n\t\tinclude: {\n\t\t\tobjectBcs: true,\n\t\t},\n\t});\n\n\tconst bcsObjects = response.objects\n\t\t.filter((obj): obj is Exclude<typeof obj, Error> => !(obj instanceof Error))\n\t\t.map((object) => object.objectBcs)\n\t\t.filter((bytes): bytes is Uint8Array<ArrayBuffer> => !!bytes);\n\n\treturn { bcsObjects };\n};\n"],"mappings":";AAMA,MAAa,kBAAkB,OAAO,aAA0B,WAA8B;CAC7F,MAAM,OAAO,YAAY,SAAS;CAElC,MAAM,eAAe,KAAK,QAAQ,SAAS,KAAK,WAAW,OAAO,SAAS,IAAI,EAAE;CACjF,MAAM,iBAAiB,KAAK,OAC1B,KAAK,UAAU;AACf,SAAO,MAAM,UAAU,YAAY,MAAM,OAAO,UAAU,qBACvD,MAAM,OAAO,iBAAiB,WAC9B;GACF,CACD,QAAQ,aAAiC,CAAC,CAAC,SAAS;AActD,QAAO,EAAE,aAZQ,MAAM,OAAO,KAAK,WAAW;EAC7C,WAAW,CAAC,GAAG,cAAc,GAAG,eAAe;EAC/C,SAAS,EACR,WAAW,MACX;EACD,CAAC,EAE0B,QAC1B,QAAQ,QAA2C,EAAE,eAAe,OAAO,CAC3E,KAAK,WAAW,OAAO,UAAU,CACjC,QAAQ,UAA4C,CAAC,CAAC,MAAM,EAEzC"}
@@ -0,0 +1,71 @@
1
+ import { p256 } from "@noble/curves/nist.js";
2
+ import { secp256k1 } from "@noble/curves/secp256k1.js";
3
+ import { ASN1Construction, ASN1TagClass, DERElement } from "asn1-ts";
4
+
5
+ //#region src/utils/utils.ts
6
+ /** The total number of bits in the DER bit string for the uncompressed public key. */
7
+ const DER_BIT_STRING_LENGTH = 520;
8
+ /** The total number of bytes corresponding to the DER bit string length. */
9
+ const DER_BYTES_LENGTH = DER_BIT_STRING_LENGTH / 8;
10
+ /**
11
+ * Converts an array of bits into a byte array.
12
+ *
13
+ * @param bitsArray - A `Uint8ClampedArray` representing the bits to convert.
14
+ * @returns A `Uint8Array` containing the corresponding bytes.
15
+ *
16
+ * @throws {Error} If the input array does not have the expected length.
17
+ */
18
+ function bitsToBytes(bitsArray) {
19
+ const bytes = new Uint8Array(DER_BYTES_LENGTH);
20
+ for (let i = 0; i < DER_BIT_STRING_LENGTH; i++) if (bitsArray[i] === 1) bytes[Math.floor(i / 8)] |= 1 << 7 - i % 8;
21
+ return bytes;
22
+ }
23
+ function publicKeyFromDER(derBytes) {
24
+ const encodedData = derBytes;
25
+ const derElement = new DERElement();
26
+ derElement.fromBytes(encodedData);
27
+ if (!(derElement.tagClass === ASN1TagClass.universal && derElement.construction === ASN1Construction.constructed)) throw new Error("Unexpected ASN.1 structure");
28
+ const publicKeyElement = derElement.components[1];
29
+ if (!publicKeyElement) throw new Error("Public Key not found in the DER structure");
30
+ return compressPublicKeyClamped(publicKeyElement.bitString);
31
+ }
32
+ function getConcatenatedSignature(signature, keyScheme) {
33
+ if (!signature || signature.length === 0) throw new Error("Invalid signature");
34
+ const derElement = new DERElement();
35
+ derElement.fromBytes(signature);
36
+ const [r, s] = derElement.toJSON();
37
+ switch (keyScheme) {
38
+ case "Secp256k1": {
39
+ const sig = new secp256k1.Signature(BigInt(r), BigInt(s));
40
+ return (sig.hasHighS() ? new secp256k1.Signature(sig.r, secp256k1.Point.Fn.neg(sig.s)) : sig).toBytes("compact");
41
+ }
42
+ case "Secp256r1": {
43
+ const sig = new p256.Signature(BigInt(r), BigInt(s));
44
+ return (sig.hasHighS() ? new p256.Signature(sig.r, p256.Point.Fn.neg(sig.s)) : sig).toBytes("compact");
45
+ }
46
+ default: throw new Error("Unsupported key scheme");
47
+ }
48
+ }
49
+ /**
50
+ * Compresses an uncompressed public key into its compressed form.
51
+ *
52
+ * The uncompressed key must follow the DER bit string format as specified in [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480#section-2.2)
53
+ * and [SEC 1: Elliptic Curve Cryptography](https://www.secg.org/sec1-v2.pdf).
54
+ *
55
+ * @param uncompressedKey - A `Uint8ClampedArray` representing the uncompressed public key bits.
56
+ * @returns A `Uint8Array` containing the compressed public key.
57
+ *
58
+ * @throws {Error} If the uncompressed key has an unexpected length or does not start with the expected prefix.
59
+ */
60
+ function compressPublicKeyClamped(uncompressedKey) {
61
+ if (uncompressedKey.length !== DER_BIT_STRING_LENGTH) throw new Error("Unexpected length for an uncompressed public key");
62
+ const uncompressedBytes = bitsToBytes(uncompressedKey);
63
+ if (uncompressedBytes[0] !== 4) throw new Error("Public key does not start with 0x04");
64
+ const xCoord = uncompressedBytes.slice(1, 33);
65
+ const parityByte = uncompressedBytes[64] % 2 === 0 ? 2 : 3;
66
+ return new Uint8Array([parityByte, ...xCoord]);
67
+ }
68
+
69
+ //#endregion
70
+ export { getConcatenatedSignature, publicKeyFromDER };
71
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","names":["secp256r1"],"sources":["../../src/utils/utils.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { p256 as secp256r1 } from '@noble/curves/nist.js';\nimport { secp256k1 } from '@noble/curves/secp256k1.js';\nimport { ASN1Construction, ASN1TagClass, DERElement } from 'asn1-ts';\n\n/** The total number of bits in the DER bit string for the uncompressed public key. */\nexport const DER_BIT_STRING_LENGTH = 520;\n\n/** The total number of bytes corresponding to the DER bit string length. */\nexport const DER_BYTES_LENGTH = DER_BIT_STRING_LENGTH / 8;\n\n// Reference Specifications:\n// https://datatracker.ietf.org/doc/html/rfc5480#section-2.2\n// https://www.secg.org/sec1-v2.pdf\n\n/**\n * Converts an array of bits into a byte array.\n *\n * @param bitsArray - A `Uint8ClampedArray` representing the bits to convert.\n * @returns A `Uint8Array` containing the corresponding bytes.\n *\n * @throws {Error} If the input array does not have the expected length.\n */\nfunction bitsToBytes(bitsArray: Uint8ClampedArray): Uint8Array {\n\tconst bytes = new Uint8Array(DER_BYTES_LENGTH);\n\tfor (let i = 0; i < DER_BIT_STRING_LENGTH; i++) {\n\t\tif (bitsArray[i] === 1) {\n\t\t\tbytes[Math.floor(i / 8)] |= 1 << (7 - (i % 8));\n\t\t}\n\t}\n\treturn bytes;\n}\n\nexport function publicKeyFromDER(derBytes: Uint8Array) {\n\tconst encodedData: Uint8Array = derBytes;\n\tconst derElement = new DERElement();\n\tderElement.fromBytes(encodedData);\n\n\t// Validate the ASN.1 structure of the public key\n\tif (\n\t\t!(\n\t\t\tderElement.tagClass === ASN1TagClass.universal &&\n\t\t\tderElement.construction === ASN1Construction.constructed\n\t\t)\n\t) {\n\t\tthrow new Error('Unexpected ASN.1 structure');\n\t}\n\n\tconst components = derElement.components;\n\tconst publicKeyElement = components[1];\n\n\tif (!publicKeyElement) {\n\t\tthrow new Error('Public Key not found in the DER structure');\n\t}\n\n\treturn compressPublicKeyClamped(publicKeyElement.bitString);\n}\n\nexport function getConcatenatedSignature(signature: Uint8Array, keyScheme: string) {\n\tif (!signature || signature.length === 0) {\n\t\tthrow new Error('Invalid signature');\n\t}\n\n\t// Initialize a DERElement to parse the DER-encoded signature\n\tconst derElement = new DERElement();\n\tderElement.fromBytes(signature);\n\n\tconst [r, s] = derElement.toJSON() as [string, string];\n\n\tswitch (keyScheme) {\n\t\tcase 'Secp256k1': {\n\t\t\tconst sig = new secp256k1.Signature(BigInt(r), BigInt(s));\n\t\t\tconst normalized = sig.hasHighS()\n\t\t\t\t? new secp256k1.Signature(sig.r, secp256k1.Point.Fn.neg(sig.s))\n\t\t\t\t: sig;\n\n\t\t\treturn normalized.toBytes('compact') as Uint8Array<ArrayBuffer>;\n\t\t}\n\t\tcase 'Secp256r1': {\n\t\t\tconst sig = new secp256r1.Signature(BigInt(r), BigInt(s));\n\t\t\tconst normalized = sig.hasHighS()\n\t\t\t\t? new secp256r1.Signature(sig.r, secp256r1.Point.Fn.neg(sig.s))\n\t\t\t\t: sig;\n\n\t\t\treturn normalized.toBytes('compact') as Uint8Array<ArrayBuffer>;\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error('Unsupported key scheme');\n\t}\n}\n\n/**\n * Compresses an uncompressed public key into its compressed form.\n *\n * The uncompressed key must follow the DER bit string format as specified in [RFC 5480](https://datatracker.ietf.org/doc/html/rfc5480#section-2.2)\n * and [SEC 1: Elliptic Curve Cryptography](https://www.secg.org/sec1-v2.pdf).\n *\n * @param uncompressedKey - A `Uint8ClampedArray` representing the uncompressed public key bits.\n * @returns A `Uint8Array` containing the compressed public key.\n *\n * @throws {Error} If the uncompressed key has an unexpected length or does not start with the expected prefix.\n */\nexport function compressPublicKeyClamped(uncompressedKey: Uint8ClampedArray): Uint8Array {\n\tif (uncompressedKey.length !== DER_BIT_STRING_LENGTH) {\n\t\tthrow new Error('Unexpected length for an uncompressed public key');\n\t}\n\n\t// Convert bits to bytes\n\tconst uncompressedBytes = bitsToBytes(uncompressedKey);\n\n\t// Ensure the public key starts with the standard uncompressed prefix 0x04\n\tif (uncompressedBytes[0] !== 0x04) {\n\t\tthrow new Error('Public key does not start with 0x04');\n\t}\n\n\t// Extract X-Coordinate (skip the first byte, which is the prefix 0x04)\n\tconst xCoord = uncompressedBytes.slice(1, 33);\n\n\t// Determine parity byte for Y coordinate based on the last byte\n\tconst yCoordLastByte = uncompressedBytes[64];\n\tconst parityByte = yCoordLastByte % 2 === 0 ? 0x02 : 0x03;\n\n\t// Return the compressed public key consisting of the parity byte and X-coordinate\n\treturn new Uint8Array([parityByte, ...xCoord]);\n}\n"],"mappings":";;;;;;AAQA,MAAa,wBAAwB;;AAGrC,MAAa,mBAAmB,wBAAwB;;;;;;;;;AAcxD,SAAS,YAAY,WAA0C;CAC9D,MAAM,QAAQ,IAAI,WAAW,iBAAiB;AAC9C,MAAK,IAAI,IAAI,GAAG,IAAI,uBAAuB,IAC1C,KAAI,UAAU,OAAO,EACpB,OAAM,KAAK,MAAM,IAAI,EAAE,KAAK,KAAM,IAAK,IAAI;AAG7C,QAAO;;AAGR,SAAgB,iBAAiB,UAAsB;CACtD,MAAM,cAA0B;CAChC,MAAM,aAAa,IAAI,YAAY;AACnC,YAAW,UAAU,YAAY;AAGjC,KACC,EACC,WAAW,aAAa,aAAa,aACrC,WAAW,iBAAiB,iBAAiB,aAG9C,OAAM,IAAI,MAAM,6BAA6B;CAI9C,MAAM,mBADa,WAAW,WACM;AAEpC,KAAI,CAAC,iBACJ,OAAM,IAAI,MAAM,4CAA4C;AAG7D,QAAO,yBAAyB,iBAAiB,UAAU;;AAG5D,SAAgB,yBAAyB,WAAuB,WAAmB;AAClF,KAAI,CAAC,aAAa,UAAU,WAAW,EACtC,OAAM,IAAI,MAAM,oBAAoB;CAIrC,MAAM,aAAa,IAAI,YAAY;AACnC,YAAW,UAAU,UAAU;CAE/B,MAAM,CAAC,GAAG,KAAK,WAAW,QAAQ;AAElC,SAAQ,WAAR;EACC,KAAK,aAAa;GACjB,MAAM,MAAM,IAAI,UAAU,UAAU,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC;AAKzD,WAJmB,IAAI,UAAU,GAC9B,IAAI,UAAU,UAAU,IAAI,GAAG,UAAU,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC,GAC7D,KAEe,QAAQ,UAAU;;EAErC,KAAK,aAAa;GACjB,MAAM,MAAM,IAAIA,KAAU,UAAU,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC;AAKzD,WAJmB,IAAI,UAAU,GAC9B,IAAIA,KAAU,UAAU,IAAI,GAAGA,KAAU,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC,GAC7D,KAEe,QAAQ,UAAU;;EAErC,QACC,OAAM,IAAI,MAAM,yBAAyB;;;;;;;;;;;;;;AAe5C,SAAgB,yBAAyB,iBAAgD;AACxF,KAAI,gBAAgB,WAAW,sBAC9B,OAAM,IAAI,MAAM,mDAAmD;CAIpE,MAAM,oBAAoB,YAAY,gBAAgB;AAGtD,KAAI,kBAAkB,OAAO,EAC5B,OAAM,IAAI,MAAM,sCAAsC;CAIvD,MAAM,SAAS,kBAAkB,MAAM,GAAG,GAAG;CAI7C,MAAM,aADiB,kBAAkB,MACL,MAAM,IAAI,IAAO;AAGrD,QAAO,IAAI,WAAW,CAAC,YAAY,GAAG,OAAO,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { SignatureScheme, Signer } from "@haneullabs/haneul/cryptography";
2
+ import { Secp256r1PublicKey } from "@haneullabs/haneul/keypairs/secp256r1";
3
+
4
+ //#region src/webcrypto/index.d.ts
5
+ interface ExportedWebCryptoKeypair {
6
+ privateKey: CryptoKey;
7
+ publicKey: Uint8Array<ArrayBuffer>;
8
+ }
9
+ declare class WebCryptoSigner extends Signer {
10
+ #private;
11
+ privateKey: CryptoKey;
12
+ static generate({
13
+ extractable
14
+ }?: {
15
+ extractable?: boolean;
16
+ }): Promise<WebCryptoSigner>;
17
+ /**
18
+ * Imports a keypair using the value returned by `export()`.
19
+ */
20
+ static import(data: ExportedWebCryptoKeypair): WebCryptoSigner;
21
+ getKeyScheme(): SignatureScheme;
22
+ constructor(privateKey: CryptoKey, publicKey: Uint8Array);
23
+ /**
24
+ * Exports the keypair so that it can be stored in IndexedDB.
25
+ */
26
+ export(): ExportedWebCryptoKeypair;
27
+ getPublicKey(): Secp256r1PublicKey;
28
+ sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
29
+ }
30
+ //#endregion
31
+ export { ExportedWebCryptoKeypair, WebCryptoSigner };
32
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/webcrypto/index.ts"],"mappings":";;;;UAuBiB,wBAAA;EAChB,UAAA,EAAY,SAAA;EACZ,SAAA,EAAW,UAAA,CAAW,WAAA;AAAA;AAAA,cAGV,eAAA,SAAwB,MAAA;EAAA;EACpC,UAAA,EAAY,SAAA;EAAA,OAIC,QAAA,CAAA;IAAW;EAAA;IAAyB,WAAA;EAAA,IAA4B,OAAA,CAAA,eAAA;EATjE;;;EAAA,OA8BL,MAAA,CAAO,IAAA,EAAM,wBAAA,GAAwB,eAAA;EAI5C,YAAA,CAAA,GAAgB,eAAA;cAIJ,UAAA,EAAY,SAAA,EAAW,SAAA,EAAW,UAAA;EAlClC;;;EA2CZ,MAAA,CAAA,GAAU,wBAAA;EAkBV,YAAA,CAAA,GAAY,kBAAA;EAIN,IAAA,CAAK,KAAA,EAAO,UAAA,GAAa,OAAA,CAAQ,UAAA,CAAW,WAAA;AAAA"}
@@ -0,0 +1,70 @@
1
+ import { Signer } from "@haneullabs/haneul/cryptography";
2
+ import { p256 } from "@noble/curves/nist.js";
3
+ import { Secp256r1PublicKey } from "@haneullabs/haneul/keypairs/secp256r1";
4
+
5
+ //#region src/webcrypto/index.ts
6
+ function getCompressedPublicKey(publicKey) {
7
+ const rawBytes = new Uint8Array(publicKey);
8
+ const x = rawBytes.slice(1, 33);
9
+ const prefix = (rawBytes.slice(33, 65)[31] & 1) === 0 ? 2 : 3;
10
+ const compressed = new Uint8Array(Secp256r1PublicKey.SIZE);
11
+ compressed[0] = prefix;
12
+ compressed.set(x, 1);
13
+ return compressed;
14
+ }
15
+ var WebCryptoSigner = class WebCryptoSigner extends Signer {
16
+ #publicKey;
17
+ static async generate({ extractable = false } = {}) {
18
+ const keypair = await globalThis.crypto.subtle.generateKey({
19
+ name: "ECDSA",
20
+ namedCurve: "P-256"
21
+ }, extractable, ["sign", "verify"]);
22
+ const publicKey = await globalThis.crypto.subtle.exportKey("raw", keypair.publicKey);
23
+ return new WebCryptoSigner(keypair.privateKey, getCompressedPublicKey(new Uint8Array(publicKey)));
24
+ }
25
+ /**
26
+ * Imports a keypair using the value returned by `export()`.
27
+ */
28
+ static import(data) {
29
+ return new WebCryptoSigner(data.privateKey, data.publicKey);
30
+ }
31
+ getKeyScheme() {
32
+ return "Secp256r1";
33
+ }
34
+ constructor(privateKey, publicKey) {
35
+ super();
36
+ this.privateKey = privateKey;
37
+ this.#publicKey = new Secp256r1PublicKey(publicKey);
38
+ }
39
+ /**
40
+ * Exports the keypair so that it can be stored in IndexedDB.
41
+ */
42
+ export() {
43
+ const exportedKeypair = {
44
+ privateKey: this.privateKey,
45
+ publicKey: this.#publicKey.toRawBytes()
46
+ };
47
+ Object.defineProperty(exportedKeypair, "toJSON", {
48
+ enumerable: false,
49
+ value: () => {
50
+ throw new Error("The exported keypair must not be serialized. It must be stored in IndexedDB directly.");
51
+ }
52
+ });
53
+ return exportedKeypair;
54
+ }
55
+ getPublicKey() {
56
+ return this.#publicKey;
57
+ }
58
+ async sign(bytes) {
59
+ const rawSignature = await globalThis.crypto.subtle.sign({
60
+ name: "ECDSA",
61
+ hash: "SHA-256"
62
+ }, this.privateKey, bytes);
63
+ const signature = p256.Signature.fromBytes(new Uint8Array(rawSignature));
64
+ return (signature.hasHighS() ? new p256.Signature(signature.r, p256.Point.Fn.neg(signature.s)) : signature).toBytes("compact");
65
+ }
66
+ };
67
+
68
+ //#endregion
69
+ export { WebCryptoSigner };
70
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["#publicKey","secp256r1"],"sources":["../../src/webcrypto/index.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { SignatureScheme } from '@haneullabs/haneul/cryptography';\nimport { Signer } from '@haneullabs/haneul/cryptography';\nimport { Secp256r1PublicKey } from '@haneullabs/haneul/keypairs/secp256r1';\nimport { p256 as secp256r1 } from '@noble/curves/nist.js';\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<ArrayBuffer>;\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\t/**\n\t * Imports a keypair using the value returned by `export()`.\n\t */\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/**\n\t * Exports the keypair so that it can be stored in IndexedDB.\n\t */\n\texport(): ExportedWebCryptoKeypair {\n\t\tconst exportedKeypair = {\n\t\t\tprivateKey: this.privateKey,\n\t\t\tpublicKey: this.#publicKey.toRawBytes(),\n\t\t};\n\n\t\tObject.defineProperty(exportedKeypair, 'toJSON', {\n\t\t\tenumerable: false,\n\t\t\tvalue: () => {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'The exported keypair must not be serialized. It must be stored in IndexedDB directly.',\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\n\t\treturn exportedKeypair;\n\t}\n\n\tgetPublicKey() {\n\t\treturn this.#publicKey;\n\t}\n\n\tasync sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>> {\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 as BufferSource,\n\t\t);\n\n\t\tconst signature = secp256r1.Signature.fromBytes(new Uint8Array(rawSignature));\n\t\tconst normalizedSig = signature.hasHighS()\n\t\t\t? new secp256r1.Signature(signature.r, secp256r1.Point.Fn.neg(signature.s))\n\t\t\t: signature;\n\n\t\treturn normalizedSig.toBytes('compact') as Uint8Array<ArrayBuffer>;\n\t}\n}\n"],"mappings":";;;;;AASA,SAAS,uBAAuB,WAAuB;CACtD,MAAM,WAAW,IAAI,WAAW,UAAU;CAC1C,MAAM,IAAI,SAAS,MAAM,GAAG,GAAG;CAG/B,MAAM,UAFI,SAAS,MAAM,IAAI,GAAG,CAEd,MAAM,OAAO,IAAI,IAAO;CAE1C,MAAM,aAAa,IAAI,WAAW,mBAAmB,KAAK;AAC1D,YAAW,KAAK;AAChB,YAAW,IAAI,GAAG,EAAE;AAEpB,QAAO;;AAQR,IAAa,kBAAb,MAAa,wBAAwB,OAAO;CAG3C;CAEA,aAAa,SAAS,EAAE,cAAc,UAAqC,EAAE,EAAE;EAC9E,MAAM,UAAU,MAAM,WAAW,OAAO,OAAO,YAC9C;GACC,MAAM;GACN,YAAY;GACZ,EACD,aACA,CAAC,QAAQ,SAAS,CAClB;EAED,MAAM,YAAY,MAAM,WAAW,OAAO,OAAO,UAAU,OAAO,QAAQ,UAAU;AAEpF,SAAO,IAAI,gBACV,QAAQ,YACR,uBAAuB,IAAI,WAAW,UAAU,CAAC,CACjD;;;;;CAMF,OAAO,OAAO,MAAgC;AAC7C,SAAO,IAAI,gBAAgB,KAAK,YAAY,KAAK,UAAU;;CAG5D,eAAgC;AAC/B,SAAO;;CAGR,YAAY,YAAuB,WAAuB;AACzD,SAAO;AACP,OAAK,aAAa;AAClB,QAAKA,YAAa,IAAI,mBAAmB,UAAU;;;;;CAMpD,SAAmC;EAClC,MAAM,kBAAkB;GACvB,YAAY,KAAK;GACjB,WAAW,MAAKA,UAAW,YAAY;GACvC;AAED,SAAO,eAAe,iBAAiB,UAAU;GAChD,YAAY;GACZ,aAAa;AACZ,UAAM,IAAI,MACT,wFACA;;GAEF,CAAC;AAEF,SAAO;;CAGR,eAAe;AACd,SAAO,MAAKA;;CAGb,MAAM,KAAK,OAAqD;EAC/D,MAAM,eAAe,MAAM,WAAW,OAAO,OAAO,KACnD;GACC,MAAM;GACN,MAAM;GACN,EACD,KAAK,YACL,MACA;EAED,MAAM,YAAYC,KAAU,UAAU,UAAU,IAAI,WAAW,aAAa,CAAC;AAK7E,UAJsB,UAAU,UAAU,GACvC,IAAIA,KAAU,UAAU,UAAU,GAAGA,KAAU,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC,GACzE,WAEkB,QAAQ,UAAU"}