@haneullabs/signers 0.1.0 → 1.0.1

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 +121 -74
  2. package/README.md +11 -8
  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 +63 -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 +71 -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 +74 -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 +8 -9
  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
@@ -1,158 +0,0 @@
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 ledger_exports = {};
27
- __export(ledger_exports, {
28
- HaneulMoveObject: () => import_bcs2.HaneulMoveObject,
29
- LedgerSigner: () => LedgerSigner,
30
- getInputObjects: () => import_objects2.getInputObjects
31
- });
32
- module.exports = __toCommonJS(ledger_exports);
33
- var import_cryptography = require("@haneullabs/haneul/cryptography");
34
- var import_ed25519 = require("@haneullabs/haneul/keypairs/ed25519");
35
- var import_transactions = require("@haneullabs/haneul/transactions");
36
- var import_utils = require("@haneullabs/haneul/utils");
37
- var import_bcs = require("@haneullabs/haneul/bcs");
38
- var import_objects = require("./objects.js");
39
- var import_bcs2 = require("./bcs.js");
40
- var import_objects2 = require("./objects.js");
41
- var _derivationPath, _publicKey, _ledgerClient, _haneulClient;
42
- const _LedgerSigner = class _LedgerSigner extends import_cryptography.Signer {
43
- /**
44
- * Creates an instance of LedgerSigner. It's expected to call the static `fromDerivationPath` method to create an instance.
45
- * @example
46
- * ```
47
- * const signer = await LedgerSigner.fromDerivationPath(derivationPath, options);
48
- * ```
49
- */
50
- constructor({ publicKey, derivationPath, ledgerClient, haneulClient }) {
51
- super();
52
- __privateAdd(this, _derivationPath);
53
- __privateAdd(this, _publicKey);
54
- __privateAdd(this, _ledgerClient);
55
- __privateAdd(this, _haneulClient);
56
- __privateSet(this, _publicKey, publicKey);
57
- __privateSet(this, _derivationPath, derivationPath);
58
- __privateSet(this, _ledgerClient, ledgerClient);
59
- __privateSet(this, _haneulClient, haneulClient);
60
- }
61
- /**
62
- * Retrieves the key scheme used by this signer.
63
- */
64
- getKeyScheme() {
65
- return "ED25519";
66
- }
67
- /**
68
- * Retrieves the public key associated with this signer.
69
- * @returns The Ed25519PublicKey instance.
70
- */
71
- getPublicKey() {
72
- return __privateGet(this, _publicKey);
73
- }
74
- /**
75
- * Signs the provided transaction bytes.
76
- * @returns The signed transaction bytes and signature.
77
- */
78
- async signTransaction(bytes, bcsObjects, resolution) {
79
- const transactionOptions = bcsObjects ? { bcsObjects } : await (0, import_objects.getInputObjects)(import_transactions.Transaction.from(bytes), __privateGet(this, _haneulClient)).catch(() => ({
80
- // Fail gracefully so network errors or serialization issues don't break transaction signing:
81
- bcsObjects: []
82
- }));
83
- const intentMessage = (0, import_cryptography.messageWithIntent)("TransactionData", bytes);
84
- const { signature } = await __privateGet(this, _ledgerClient).signTransaction(
85
- __privateGet(this, _derivationPath),
86
- intentMessage,
87
- transactionOptions,
88
- resolution
89
- );
90
- return {
91
- bytes: (0, import_utils.toBase64)(bytes),
92
- signature: (0, import_cryptography.toSerializedSignature)({
93
- signature,
94
- signatureScheme: this.getKeyScheme(),
95
- publicKey: __privateGet(this, _publicKey)
96
- })
97
- };
98
- }
99
- /**
100
- * Signs the provided personal message.
101
- * @returns The signed message bytes and signature.
102
- */
103
- async signPersonalMessage(bytes) {
104
- const intentMessage = (0, import_cryptography.messageWithIntent)(
105
- "PersonalMessage",
106
- import_bcs.bcs.byteVector().serialize(bytes).toBytes()
107
- );
108
- const { signature } = await __privateGet(this, _ledgerClient).signTransaction(
109
- __privateGet(this, _derivationPath),
110
- intentMessage
111
- );
112
- return {
113
- bytes: (0, import_utils.toBase64)(bytes),
114
- signature: (0, import_cryptography.toSerializedSignature)({
115
- signature,
116
- signatureScheme: this.getKeyScheme(),
117
- publicKey: __privateGet(this, _publicKey)
118
- })
119
- };
120
- }
121
- /**
122
- * Prepares the signer by fetching and setting the public key from a Ledger device.
123
- * It is recommended to initialize an `LedgerSigner` instance using this function.
124
- * @returns A promise that resolves once a `LedgerSigner` instance is prepared (public key is set).
125
- */
126
- static async fromDerivationPath(derivationPath, ledgerClient, haneulClient) {
127
- const { publicKey } = await ledgerClient.getPublicKey(derivationPath);
128
- if (!publicKey) {
129
- throw new Error("Failed to get public key from Ledger.");
130
- }
131
- return new _LedgerSigner({
132
- derivationPath,
133
- publicKey: new import_ed25519.Ed25519PublicKey(publicKey),
134
- ledgerClient,
135
- haneulClient
136
- });
137
- }
138
- /**
139
- * Generic signing is not supported by Ledger.
140
- * @throws Always throws an error indicating generic signing is unsupported.
141
- */
142
- sign() {
143
- throw new Error("Ledger Signer does not support generic signing.");
144
- }
145
- /**
146
- * Generic signing is not supported by Ledger.
147
- * @throws Always throws an error indicating generic signing is unsupported.
148
- */
149
- signWithIntent() {
150
- throw new Error("Ledger Signer does not support generic signing.");
151
- }
152
- };
153
- _derivationPath = new WeakMap();
154
- _publicKey = new WeakMap();
155
- _ledgerClient = new WeakMap();
156
- _haneulClient = new WeakMap();
157
- let LedgerSigner = _LedgerSigner;
158
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/ledger/index.ts"],
4
- "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 { HaneulClient } 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 { HaneulMoveObject } from './bcs.js';\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: HaneulClient;\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: HaneulClient;\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: HaneulClient,\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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,0BAAiE;AACjE,qBAAiC;AACjC,0BAA4B;AAC5B,mBAAyB;AAEzB,iBAAoB;AACpB,qBAAgC;AAGhC,IAAAA,cAAiC;AACjC,IAAAC,kBAAgC;AAhBhC;AA+BO,MAAM,gBAAN,MAAM,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A,MACrB,eAAW,2CAAsB;AAAA,QAChC;AAAA,QACA,iBAAiB,KAAK,aAAa;AAAA,QACnC,WAAW,mBAAK;AAAA,MACjB,CAAC;AAAA,IACF;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAa,mBACZ,gBACA,cACA,cACC;AACD,UAAM,EAAE,UAAU,IAAI,MAAM,aAAa,aAAa,cAAc;AACpE,QAAI,CAAC,WAAW;AACf,YAAM,IAAI,MAAM,uCAAuC;AAAA,IACxD;AAEA,WAAO,IAAI,cAAa;AAAA,MACvB;AAAA,MACA,WAAW,IAAI,gCAAiB,SAAS;AAAA,MACzC;AAAA,MACA;AAAA,IACD,CAAC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMS,OAAc;AACtB,UAAM,IAAI,MAAM,iDAAiD;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMS,iBAAwB;AAChC,UAAM,IAAI,MAAM,iDAAiD;AAAA,EAClE;AACD;AAnIC;AACA;AACA;AACA;AAJM,IAAM,eAAN;",
6
- "names": ["import_bcs", "import_objects"]
7
- }
@@ -1,5 +0,0 @@
1
- import type { Transaction } from '@haneullabs/haneul/transactions';
2
- import type { HaneulClient } from '@haneullabs/haneul/client';
3
- export declare const getInputObjects: (transaction: Transaction, client: HaneulClient) => Promise<{
4
- bcsObjects: Uint8Array<ArrayBuffer>[];
5
- }>;
@@ -1,60 +0,0 @@
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 __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var objects_exports = {};
20
- __export(objects_exports, {
21
- getInputObjects: () => getInputObjects
22
- });
23
- module.exports = __toCommonJS(objects_exports);
24
- var import_bcs = require("./bcs.js");
25
- const getInputObjects = async (transaction, client) => {
26
- const data = transaction.getData();
27
- const gasObjectIds = data.gasData.payment?.map((object) => object.objectId) ?? [];
28
- const inputObjectIds = data.inputs.map((input) => {
29
- return input.$kind === "Object" && input.Object.$kind === "ImmOrOwnedObject" ? input.Object.ImmOrOwnedObject.objectId : null;
30
- }).filter((objectId) => !!objectId);
31
- const objects = await client.multiGetObjects({
32
- ids: [...gasObjectIds, ...inputObjectIds],
33
- options: {
34
- showBcs: true,
35
- showPreviousTransaction: true,
36
- showStorageRebate: true,
37
- showOwner: true
38
- }
39
- });
40
- const bcsObjects = objects.map((object) => {
41
- if (object.error || !object.data || object.data.bcs?.dataType !== "moveObject") {
42
- return null;
43
- }
44
- return import_bcs.HaneulMoveObject.serialize({
45
- data: {
46
- MoveObject: {
47
- type: object.data.bcs.type,
48
- hasPublicTransfer: object.data.bcs.hasPublicTransfer,
49
- version: object.data.bcs.version,
50
- contents: object.data.bcs.bcsBytes
51
- }
52
- },
53
- owner: object.data.owner,
54
- previousTransaction: object.data.previousTransaction,
55
- storageRebate: object.data.storageRebate
56
- }).toBytes();
57
- }).filter((bcsBytes) => !!bcsBytes);
58
- return { bcsObjects };
59
- };
60
- //# sourceMappingURL=objects.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/ledger/objects.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction } from '@haneullabs/haneul/transactions';\nimport type { HaneulClient } from '@haneullabs/haneul/client';\nimport { HaneulMoveObject } from './bcs.js';\n\nexport const getInputObjects = async (transaction: Transaction, client: HaneulClient) => {\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 objects = await client.multiGetObjects({\n\t\tids: [...gasObjectIds, ...inputObjectIds],\n\t\toptions: {\n\t\t\tshowBcs: true,\n\t\t\tshowPreviousTransaction: true,\n\t\t\tshowStorageRebate: true,\n\t\t\tshowOwner: true,\n\t\t},\n\t});\n\n\t// NOTE: We should probably get rid of this manual serialization logic in favor of using the\n\t// already serialized object bytes from the GraphQL API once there is more mainstream support\n\t// for it + we can enforce the transport type on the Haneul client.\n\tconst bcsObjects = objects\n\t\t.map((object) => {\n\t\t\tif (object.error || !object.data || object.data.bcs?.dataType !== 'moveObject') {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn HaneulMoveObject.serialize({\n\t\t\t\tdata: {\n\t\t\t\t\tMoveObject: {\n\t\t\t\t\t\ttype: object.data.bcs.type,\n\t\t\t\t\t\thasPublicTransfer: object.data.bcs.hasPublicTransfer,\n\t\t\t\t\t\tversion: object.data.bcs.version,\n\t\t\t\t\t\tcontents: object.data.bcs.bcsBytes,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\towner: object.data.owner!,\n\t\t\t\tpreviousTransaction: object.data.previousTransaction!,\n\t\t\t\tstorageRebate: object.data.storageRebate!,\n\t\t\t}).toBytes();\n\t\t})\n\t\t.filter((bcsBytes): bcsBytes is Uint8Array<ArrayBuffer> => !!bcsBytes);\n\n\treturn { bcsObjects };\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;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js",
4
- "sideEffects": false
5
- }
@@ -1,18 +0,0 @@
1
- /** The total number of bits in the DER bit string for the uncompressed public key. */
2
- export declare const DER_BIT_STRING_LENGTH = 520;
3
- /** The total number of bytes corresponding to the DER bit string length. */
4
- export declare const DER_BYTES_LENGTH: number;
5
- export declare function publicKeyFromDER(derBytes: Uint8Array): Uint8Array<ArrayBufferLike>;
6
- export declare function getConcatenatedSignature(signature: Uint8Array, keyScheme: string): Uint8Array<ArrayBuffer>;
7
- /**
8
- * Compresses an uncompressed public key into its compressed form.
9
- *
10
- * 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)
11
- * and [SEC 1: Elliptic Curve Cryptography](https://www.secg.org/sec1-v2.pdf).
12
- *
13
- * @param uncompressedKey - A `Uint8ClampedArray` representing the uncompressed public key bits.
14
- * @returns A `Uint8Array` containing the compressed public key.
15
- *
16
- * @throws {Error} If the uncompressed key has an unexpected length or does not start with the expected prefix.
17
- */
18
- export declare function compressPublicKeyClamped(uncompressedKey: Uint8ClampedArray): Uint8Array;
@@ -1,85 +0,0 @@
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 __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var utils_exports = {};
20
- __export(utils_exports, {
21
- DER_BIT_STRING_LENGTH: () => DER_BIT_STRING_LENGTH,
22
- DER_BYTES_LENGTH: () => DER_BYTES_LENGTH,
23
- compressPublicKeyClamped: () => compressPublicKeyClamped,
24
- getConcatenatedSignature: () => getConcatenatedSignature,
25
- publicKeyFromDER: () => publicKeyFromDER
26
- });
27
- module.exports = __toCommonJS(utils_exports);
28
- var import_p256 = require("@noble/curves/p256");
29
- var import_secp256k1 = require("@noble/curves/secp256k1");
30
- var import_asn1_ts = require("asn1-ts");
31
- const DER_BIT_STRING_LENGTH = 520;
32
- const DER_BYTES_LENGTH = DER_BIT_STRING_LENGTH / 8;
33
- function bitsToBytes(bitsArray) {
34
- const bytes = new Uint8Array(DER_BYTES_LENGTH);
35
- for (let i = 0; i < DER_BIT_STRING_LENGTH; i++) {
36
- if (bitsArray[i] === 1) {
37
- bytes[Math.floor(i / 8)] |= 1 << 7 - i % 8;
38
- }
39
- }
40
- return bytes;
41
- }
42
- function publicKeyFromDER(derBytes) {
43
- const encodedData = derBytes;
44
- const derElement = new import_asn1_ts.DERElement();
45
- derElement.fromBytes(encodedData);
46
- if (!(derElement.tagClass === import_asn1_ts.ASN1TagClass.universal && derElement.construction === import_asn1_ts.ASN1Construction.constructed)) {
47
- throw new Error("Unexpected ASN.1 structure");
48
- }
49
- const components = derElement.components;
50
- const publicKeyElement = components[1];
51
- if (!publicKeyElement) {
52
- throw new Error("Public Key not found in the DER structure");
53
- }
54
- return compressPublicKeyClamped(publicKeyElement.bitString);
55
- }
56
- function getConcatenatedSignature(signature, keyScheme) {
57
- if (!signature || signature.length === 0) {
58
- throw new Error("Invalid signature");
59
- }
60
- const derElement = new import_asn1_ts.DERElement();
61
- derElement.fromBytes(signature);
62
- const [r, s] = derElement.toJSON();
63
- switch (keyScheme) {
64
- case "Secp256k1":
65
- return new import_secp256k1.secp256k1.Signature(BigInt(r), BigInt(s)).normalizeS().toCompactRawBytes();
66
- case "Secp256r1":
67
- return new import_p256.secp256r1.Signature(BigInt(r), BigInt(s)).normalizeS().toCompactRawBytes();
68
- default:
69
- throw new Error("Unsupported key scheme");
70
- }
71
- }
72
- function compressPublicKeyClamped(uncompressedKey) {
73
- if (uncompressedKey.length !== DER_BIT_STRING_LENGTH) {
74
- throw new Error("Unexpected length for an uncompressed public key");
75
- }
76
- const uncompressedBytes = bitsToBytes(uncompressedKey);
77
- if (uncompressedBytes[0] !== 4) {
78
- throw new Error("Public key does not start with 0x04");
79
- }
80
- const xCoord = uncompressedBytes.slice(1, 33);
81
- const yCoordLastByte = uncompressedBytes[64];
82
- const parityByte = yCoordLastByte % 2 === 0 ? 2 : 3;
83
- return new Uint8Array([parityByte, ...xCoord]);
84
- }
85
- //# sourceMappingURL=utils.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/utils/utils.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { secp256r1 } from '@noble/curves/p256';\nimport { secp256k1 } from '@noble/curves/secp256k1';\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\treturn new secp256k1.Signature(BigInt(r), BigInt(s))\n\t\t\t\t.normalizeS()\n\t\t\t\t.toCompactRawBytes() as Uint8Array<ArrayBuffer>;\n\t\tcase 'Secp256r1':\n\t\t\treturn new secp256r1.Signature(BigInt(r), BigInt(s))\n\t\t\t\t.normalizeS()\n\t\t\t\t.toCompactRawBytes() as Uint8Array<ArrayBuffer>;\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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAC1B,uBAA0B;AAC1B,qBAA2D;AAGpD,MAAM,wBAAwB;AAG9B,MAAM,mBAAmB,wBAAwB;AAcxD,SAAS,YAAY,WAA0C;AAC9D,QAAM,QAAQ,IAAI,WAAW,gBAAgB;AAC7C,WAAS,IAAI,GAAG,IAAI,uBAAuB,KAAK;AAC/C,QAAI,UAAU,CAAC,MAAM,GAAG;AACvB,YAAM,KAAK,MAAM,IAAI,CAAC,CAAC,KAAK,KAAM,IAAK,IAAI;AAAA,IAC5C;AAAA,EACD;AACA,SAAO;AACR;AAEO,SAAS,iBAAiB,UAAsB;AACtD,QAAM,cAA0B;AAChC,QAAM,aAAa,IAAI,0BAAW;AAClC,aAAW,UAAU,WAAW;AAGhC,MACC,EACC,WAAW,aAAa,4BAAa,aACrC,WAAW,iBAAiB,gCAAiB,cAE7C;AACD,UAAM,IAAI,M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@haneullabs/haneul/cryptography';
3
- import { Secp256r1PublicKey } from '@haneullabs/haneul/keypairs/secp256r1';
4
- export interface ExportedWebCryptoKeypair {
5
- privateKey: CryptoKey;
6
- publicKey: Uint8Array<ArrayBuffer>;
7
- }
8
- export declare class WebCryptoSigner extends Signer {
9
- #private;
10
- privateKey: CryptoKey;
11
- static generate({ extractable }?: {
12
- extractable?: boolean;
13
- }): Promise<WebCryptoSigner>;
14
- /**
15
- * Imports a keypair using the value returned by `export()`.
16
- */
17
- static import(data: ExportedWebCryptoKeypair): WebCryptoSigner;
18
- getKeyScheme(): SignatureScheme;
19
- constructor(privateKey: CryptoKey, publicKey: Uint8Array);
20
- /**
21
- * Exports the keypair so that it can be stored in IndexedDB.
22
- */
23
- export(): ExportedWebCryptoKeypair;
24
- getPublicKey(): Secp256r1PublicKey;
25
- sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
26
- }
@@ -1,112 +0,0 @@
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("@haneullabs/haneul/cryptography");
32
- var import_secp256r1 = require("@haneullabs/haneul/keypairs/secp256r1");
33
- var import_p256 = require("@noble/curves/p256");
34
- var _publicKey;
35
- function getCompressedPublicKey(publicKey) {
36
- const rawBytes = new Uint8Array(publicKey);
37
- const x = rawBytes.slice(1, 33);
38
- const y = rawBytes.slice(33, 65);
39
- const prefix = (y[31] & 1) === 0 ? 2 : 3;
40
- const compressed = new Uint8Array(import_secp256r1.Secp256r1PublicKey.SIZE);
41
- compressed[0] = prefix;
42
- compressed.set(x, 1);
43
- return compressed;
44
- }
45
- const _WebCryptoSigner = class _WebCryptoSigner extends import_cryptography.Signer {
46
- constructor(privateKey, publicKey) {
47
- super();
48
- __privateAdd(this, _publicKey);
49
- this.privateKey = privateKey;
50
- __privateSet(this, _publicKey, new import_secp256r1.Secp256r1PublicKey(publicKey));
51
- }
52
- static async generate({ extractable = false } = {}) {
53
- const keypair = await globalThis.crypto.subtle.generateKey(
54
- {
55
- name: "ECDSA",
56
- namedCurve: "P-256"
57
- },
58
- extractable,
59
- ["sign", "verify"]
60
- );
61
- const publicKey = await globalThis.crypto.subtle.exportKey("raw", keypair.publicKey);
62
- return new _WebCryptoSigner(
63
- keypair.privateKey,
64
- getCompressedPublicKey(new Uint8Array(publicKey))
65
- );
66
- }
67
- /**
68
- * Imports a keypair using the value returned by `export()`.
69
- */
70
- static import(data) {
71
- return new _WebCryptoSigner(data.privateKey, data.publicKey);
72
- }
73
- getKeyScheme() {
74
- return "Secp256r1";
75
- }
76
- /**
77
- * Exports the keypair so that it can be stored in IndexedDB.
78
- */
79
- export() {
80
- const exportedKeypair = {
81
- privateKey: this.privateKey,
82
- publicKey: __privateGet(this, _publicKey).toRawBytes()
83
- };
84
- Object.defineProperty(exportedKeypair, "toJSON", {
85
- enumerable: false,
86
- value: () => {
87
- throw new Error(
88
- "The exported keypair must not be serialized. It must be stored in IndexedDB directly."
89
- );
90
- }
91
- });
92
- return exportedKeypair;
93
- }
94
- getPublicKey() {
95
- return __privateGet(this, _publicKey);
96
- }
97
- async sign(bytes) {
98
- const rawSignature = await globalThis.crypto.subtle.sign(
99
- {
100
- name: "ECDSA",
101
- hash: "SHA-256"
102
- },
103
- this.privateKey,
104
- bytes
105
- );
106
- const signature = import_p256.secp256r1.Signature.fromCompact(new Uint8Array(rawSignature));
107
- return signature.normalizeS().toCompactRawBytes();
108
- }
109
- };
110
- _publicKey = new WeakMap();
111
- let WebCryptoSigner = _WebCryptoSigner;
112
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
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 '@haneullabs/haneul/cryptography';\nimport { Signer } from '@haneullabs/haneul/cryptography';\nimport { Secp256r1PublicKey } from '@haneullabs/haneul/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<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.fromCompact(new Uint8Array(rawSignature));\n\n\t\treturn signature.normalizeS().toCompactRawBytes() as Uint8Array<ArrayBuffer>;\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,MAAM,yBAAwB,2BAAO;AAAA,EAkC3C,YAAY,YAAuB,WAAuB;AACzD,UAAM;AAhCP;AAiCC,SAAK,aAAa;AAClB,uBAAK,YAAa,IAAI,oCAAmB,SAAS;AAAA,EACnD;AAAA,EAjCA,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;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,OAAO,MAAgC;AAC7C,WAAO,IAAI,iBAAgB,KAAK,YAAY,KAAK,SAAS;AAAA,EAC3D;AAAA,EAEA,eAAgC;AAC/B,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAWA,SAAmC;AAClC,UAAM,kBAAkB;AAAA,MACvB,YAAY,KAAK;AAAA,MACjB,WAAW,mBAAK,YAAW,WAAW;AAAA,IACvC;AAEA,WAAO,eAAe,iBAAiB,UAAU;AAAA,MAChD,YAAY;AAAA,MACZ,OAAO,MAAM;AACZ,cAAM,IAAI;AAAA,UACT;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAC;AAED,WAAO;AAAA,EACR;AAAA,EAEA,eAAe;AACd,WAAO,mBAAK;AAAA,EACb;AAAA,EAEA,MAAM,KAAK,OAAqD;AAC/D,UAAM,eAAe,MAAM,WAAW,OAAO,OAAO;AAAA,MACnD;AAAA,QACC,MAAM;AAAA,QACN,MAAM;AAAA,MACP;AAAA,MACA,KAAK;AAAA,MACL;AAAA,IACD;AAEA,UAAM,YAAY,sBAAU,UAAU,YAAY,IAAI,WAAW,YAAY,CAAC;AAE9E,WAAO,UAAU,WAAW,EAAE,kBAAkB;AAAA,EACjD;AACD;AA5EC;AAHM,IAAM,kBAAN;",
6
- "names": []
7
- }
@@ -1,43 +0,0 @@
1
- import { Secp256k1PublicKey } from '@haneullabs/haneul/keypairs/secp256k1';
2
- import { Secp256r1PublicKey } from '@haneullabs/haneul/keypairs/secp256r1';
3
- import { AwsClient } from './aws4fetch.js';
4
- interface KmsCommands {
5
- Sign: {
6
- request: {
7
- KeyId: string;
8
- Message: string;
9
- MessageType: 'RAW' | 'DIGEST';
10
- SigningAlgorithm: 'ECDSA_SHA_256';
11
- };
12
- response: {
13
- KeyId: string;
14
- KeyOrigin: string;
15
- Signature: string;
16
- SigningAlgorithm: string;
17
- };
18
- };
19
- GetPublicKey: {
20
- request: {
21
- KeyId: string;
22
- };
23
- response: {
24
- CustomerMasterKeySpec: string;
25
- KeyId: string;
26
- KeyOrigin: string;
27
- KeySpec: string;
28
- KeyUsage: string;
29
- PublicKey: string;
30
- SigningAlgorithms: string[];
31
- };
32
- };
33
- }
34
- export interface AwsClientOptions extends Partial<ConstructorParameters<typeof AwsClient>[0]> {
35
- }
36
- export declare class AwsKmsClient extends AwsClient {
37
- constructor(options?: AwsClientOptions);
38
- getPublicKey(keyId: string): Promise<Secp256r1PublicKey | Secp256k1PublicKey>;
39
- runCommand<T extends keyof KmsCommands>(command: T, body: KmsCommands[T]['request'], { region, }?: {
40
- region?: string;
41
- }): Promise<KmsCommands[T]['response']>;
42
- }
43
- export {};
@@ -1,59 +0,0 @@
1
- import { Secp256k1PublicKey } from "@haneullabs/haneul/keypairs/secp256k1";
2
- import { Secp256r1PublicKey } from "@haneullabs/haneul/keypairs/secp256r1";
3
- import { fromBase64 } from "@haneullabs/haneul/utils";
4
- import { publicKeyFromDER } from "../utils/utils.js";
5
- import { AwsClient } from "./aws4fetch.js";
6
- class AwsKmsClient extends AwsClient {
7
- constructor(options = {}) {
8
- if (!options.accessKeyId || !options.secretAccessKey) {
9
- throw new Error("AWS Access Key ID and Secret Access Key are required");
10
- }
11
- if (!options.region) {
12
- throw new Error("Region is required");
13
- }
14
- super({
15
- region: options.region,
16
- accessKeyId: options.accessKeyId,
17
- secretAccessKey: options.secretAccessKey,
18
- service: "kms",
19
- ...options
20
- });
21
- }
22
- async getPublicKey(keyId) {
23
- const publicKeyResponse = await this.runCommand("GetPublicKey", { KeyId: keyId });
24
- if (!publicKeyResponse.PublicKey) {
25
- throw new Error("Public Key not found for the supplied `keyId`");
26
- }
27
- const compressedKey = publicKeyFromDER(fromBase64(publicKeyResponse.PublicKey));
28
- switch (publicKeyResponse.KeySpec) {
29
- case "ECC_NIST_P256":
30
- return new Secp256r1PublicKey(compressedKey);
31
- case "ECC_SECG_P256K1":
32
- return new Secp256k1PublicKey(compressedKey);
33
- default:
34
- throw new Error("Unsupported key spec: " + publicKeyResponse.KeySpec);
35
- }
36
- }
37
- async runCommand(command, body, {
38
- region = this.region
39
- } = {}) {
40
- if (!region) {
41
- throw new Error("Region is required");
42
- }
43
- const res = await this.fetch(`https://kms.${region}.amazonaws.com/`, {
44
- headers: {
45
- "Content-Type": "application/x-amz-json-1.1",
46
- "X-Amz-Target": `TrentService.${command}`
47
- },
48
- body: JSON.stringify(body)
49
- });
50
- if (!res.ok) {
51
- throw new Error(await res.text());
52
- }
53
- return res.json();
54
- }
55
- }
56
- export {
57
- AwsKmsClient
58
- };
59
- //# sourceMappingURL=aws-client.js.map