@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
@@ -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('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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"}
package/package.json CHANGED
@@ -1,26 +1,30 @@
1
1
  {
2
2
  "name": "@haneullabs/signers",
3
- "version": "0.1.0",
3
+ "version": "1.0.1",
4
4
  "description": "A collection of signers for various providers",
5
5
  "license": "Apache-2.0",
6
- "author": "Haneul Labs <build@haneullabs.com>",
7
- "type": "commonjs",
6
+ "author": "Haneul Labs <build@haneul-labs.com>",
7
+ "type": "module",
8
8
  "exports": {
9
9
  "./aws": {
10
- "import": "./dist/esm/aws/index.js",
11
- "require": "./dist/cjs/aws/index.js"
10
+ "types": "./dist/aws/index.d.mts",
11
+ "import": "./dist/aws/index.mjs",
12
+ "default": "./dist/aws/index.mjs"
12
13
  },
13
14
  "./gcp": {
14
- "import": "./dist/esm/gcp/index.js",
15
- "require": "./dist/cjs/gcp/index.js"
15
+ "types": "./dist/gcp/index.d.mts",
16
+ "import": "./dist/gcp/index.mjs",
17
+ "default": "./dist/gcp/index.mjs"
16
18
  },
17
19
  "./ledger": {
18
- "import": "./dist/esm/ledger/index.js",
19
- "require": "./dist/cjs/ledger/index.js"
20
+ "types": "./dist/ledger/index.d.mts",
21
+ "import": "./dist/ledger/index.mjs",
22
+ "default": "./dist/ledger/index.mjs"
20
23
  },
21
24
  "./webcrypto": {
22
- "import": "./dist/esm/webcrypto/index.js",
23
- "require": "./dist/cjs/webcrypto/index.js"
25
+ "types": "./dist/webcrypto/index.d.mts",
26
+ "import": "./dist/webcrypto/index.mjs",
27
+ "default": "./dist/webcrypto/index.mjs"
24
28
  }
25
29
  },
26
30
  "sideEffects": false,
@@ -38,39 +42,41 @@
38
42
  ],
39
43
  "repository": {
40
44
  "type": "git",
41
- "url": "git+https://github.com/GeunhwaJeong/haneul-ts-sdks.git"
45
+ "url": "git+https://github.com/GeunhwaJeong/ts-sdks.git"
42
46
  },
43
47
  "bugs": {
44
- "url": "https://github.com/haneullabs/ts-sdks/issues"
48
+ "url": "https://github.com/mystenlabs/ts-sdks/issues"
45
49
  },
46
- "homepage": "https://github.com/GeunhwaJeong/haneul-ts-sdks/tree/main/packages/signers#readme",
50
+ "homepage": "https://github.com/GeunhwaJeong/ts-sdks/tree/main/packages/signers#readme",
47
51
  "devDependencies": {
48
- "@types/node": "^24.10.1",
52
+ "@types/node": "^25.0.8",
49
53
  "dotenv": "^17.2.3",
50
54
  "typescript": "^5.9.3",
51
- "vitest": "^4.0.15",
52
- "@haneullabs/build-scripts": "0.1.0"
55
+ "vitest": "^4.0.17",
56
+ "@haneullabs/haneul": "^2.4.0"
53
57
  },
54
58
  "dependencies": {
55
- "@google-cloud/kms": "^4.5.0",
56
- "@noble/curves": "=1.9.4",
57
- "@noble/hashes": "^1.8.0",
58
- "asn1-ts": "^8.0.2",
59
- "@haneullabs/haneul": "0.1.0",
60
- "@haneullabs/ledgerjs-hw-app-haneul": "0.1.0"
59
+ "@google-cloud/kms": "^5.2.1",
60
+ "@noble/curves": "^2.0.1",
61
+ "@noble/hashes": "^2.0.1",
62
+ "asn1-ts": "^11.0.5",
63
+ "@haneullabs/ledgerjs-hw-app-haneul": "^0.7.1"
61
64
  },
62
65
  "engines": {
63
- "node": ">=20"
66
+ "node": ">=22"
67
+ },
68
+ "peerDependencies": {
69
+ "@haneullabs/haneul": "^2.4.0"
64
70
  },
65
71
  "scripts": {
66
72
  "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
67
- "build": "build-package",
73
+ "build": "rm -rf dist && tsc --noEmit && tsdown",
68
74
  "prettier:check": "prettier -c --ignore-unknown .",
69
75
  "prettier:fix": "prettier -w --ignore-unknown .",
70
- "eslint:check": "eslint --max-warnings=0 .",
71
- "eslint:fix": "pnpm run eslint:check --fix",
72
- "lint": "pnpm run eslint:check && pnpm run prettier:check",
73
- "lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix",
76
+ "oxlint:check": "oxlint .",
77
+ "oxlint:fix": "oxlint --fix",
78
+ "lint": "pnpm run oxlint:check && pnpm run prettier:check",
79
+ "lint:fix": "pnpm run oxlint:fix && pnpm run prettier:fix",
74
80
  "test": "vitest run"
75
81
  }
76
82
  }
@@ -83,15 +83,6 @@ export class AwsKmsSigner extends Signer {
83
83
  return getConcatenatedSignature(fromBase64(signResponse.Signature), this.getKeyScheme());
84
84
  }
85
85
 
86
- /**
87
- * Synchronous signing is not supported by AWS KMS.
88
- * @throws Always throws an error indicating synchronous signing is unsupported.
89
- * @deprecated use `sign` instead
90
- */
91
- signData(): never {
92
- throw new Error('KMS Signer does not support sync signing');
93
- }
94
-
95
86
  /**
96
87
  * Prepares the signer by fetching and setting the public key from AWS KMS.
97
88
  * It is recommended to initialize an `AwsKmsSigner` instance using this function.
@@ -86,15 +86,6 @@ export class GcpKmsSigner extends Signer {
86
86
  return getConcatenatedSignature(signResponse.signature as Uint8Array, this.getKeyScheme());
87
87
  }
88
88
 
89
- /**
90
- * Synchronous signing is not supported by GCP KMS.
91
- * @throws Always throws an error indicating synchronous signing is unsupported.
92
- * @deprecated use `sign` instead
93
- */
94
- signData(): never {
95
- throw new Error('GCP Signer does not support sync signing');
96
- }
97
-
98
89
  /**
99
90
  * Creates a GCP KMS signer from the provided options.
100
91
  * Expects the credentials file to be set as an env variable
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type HaneulLedgerClient from '@haneullabs/ledgerjs-hw-app-haneul';
5
- import type { HaneulClient } from '@haneullabs/haneul/client';
5
+ import type { ClientWithCoreApi } from '@haneullabs/haneul/client';
6
6
  import type { SignatureWithBytes } from '@haneullabs/haneul/cryptography';
7
7
  import { messageWithIntent, Signer, toSerializedSignature } from '@haneullabs/haneul/cryptography';
8
8
  import { Ed25519PublicKey } from '@haneullabs/haneul/keypairs/ed25519';
@@ -13,7 +13,6 @@ import { bcs } from '@haneullabs/haneul/bcs';
13
13
  import { getInputObjects } from './objects.js';
14
14
  import type { Resolution } from '@haneullabs/ledgerjs-hw-app-haneul';
15
15
 
16
- export { HaneulMoveObject } from './bcs.js';
17
16
  export { getInputObjects } from './objects.js';
18
17
 
19
18
  /**
@@ -23,7 +22,7 @@ export interface LedgerSignerOptions {
23
22
  publicKey: Ed25519PublicKey;
24
23
  derivationPath: string;
25
24
  ledgerClient: HaneulLedgerClient;
26
- haneulClient: HaneulClient;
25
+ suiClient: ClientWithCoreApi;
27
26
  }
28
27
 
29
28
  /**
@@ -33,7 +32,7 @@ export class LedgerSigner extends Signer {
33
32
  #derivationPath: string;
34
33
  #publicKey: Ed25519PublicKey;
35
34
  #ledgerClient: HaneulLedgerClient;
36
- #haneulClient: HaneulClient;
35
+ #suiClient: ClientWithCoreApi;
37
36
 
38
37
  /**
39
38
  * Creates an instance of LedgerSigner. It's expected to call the static `fromDerivationPath` method to create an instance.
@@ -42,12 +41,12 @@ export class LedgerSigner extends Signer {
42
41
  * const signer = await LedgerSigner.fromDerivationPath(derivationPath, options);
43
42
  * ```
44
43
  */
45
- constructor({ publicKey, derivationPath, ledgerClient, haneulClient }: LedgerSignerOptions) {
44
+ constructor({ publicKey, derivationPath, ledgerClient, suiClient }: LedgerSignerOptions) {
46
45
  super();
47
46
  this.#publicKey = publicKey;
48
47
  this.#derivationPath = derivationPath;
49
48
  this.#ledgerClient = ledgerClient;
50
- this.#haneulClient = haneulClient;
49
+ this.#suiClient = suiClient;
51
50
  }
52
51
 
53
52
  /**
@@ -76,7 +75,7 @@ export class LedgerSigner extends Signer {
76
75
  ): Promise<SignatureWithBytes> {
77
76
  const transactionOptions = bcsObjects
78
77
  ? { bcsObjects }
79
- : await getInputObjects(Transaction.from(bytes), this.#haneulClient).catch(() => ({
78
+ : await getInputObjects(Transaction.from(bytes), this.#suiClient).catch(() => ({
80
79
  // Fail gracefully so network errors or serialization issues don't break transaction signing:
81
80
  bcsObjects: [],
82
81
  }));
@@ -131,7 +130,7 @@ export class LedgerSigner extends Signer {
131
130
  static async fromDerivationPath(
132
131
  derivationPath: string,
133
132
  ledgerClient: HaneulLedgerClient,
134
- haneulClient: HaneulClient,
133
+ suiClient: ClientWithCoreApi,
135
134
  ) {
136
135
  const { publicKey } = await ledgerClient.getPublicKey(derivationPath);
137
136
  if (!publicKey) {
@@ -142,7 +141,7 @@ export class LedgerSigner extends Signer {
142
141
  derivationPath,
143
142
  publicKey: new Ed25519PublicKey(publicKey),
144
143
  ledgerClient,
145
- haneulClient,
144
+ suiClient,
146
145
  });
147
146
  }
148
147
 
@@ -2,10 +2,9 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type { Transaction } from '@haneullabs/haneul/transactions';
5
- import type { HaneulClient } from '@haneullabs/haneul/client';
6
- import { HaneulMoveObject } from './bcs.js';
5
+ import type { ClientWithCoreApi } from '@haneullabs/haneul/client';
7
6
 
8
- export const getInputObjects = async (transaction: Transaction, client: HaneulClient) => {
7
+ export const getInputObjects = async (transaction: Transaction, client: ClientWithCoreApi) => {
9
8
  const data = transaction.getData();
10
9
 
11
10
  const gasObjectIds = data.gasData.payment?.map((object) => object.objectId) ?? [];
@@ -17,40 +16,17 @@ export const getInputObjects = async (transaction: Transaction, client: HaneulCl
17
16
  })
18
17
  .filter((objectId): objectId is string => !!objectId);
19
18
 
20
- const objects = await client.multiGetObjects({
21
- ids: [...gasObjectIds, ...inputObjectIds],
22
- options: {
23
- showBcs: true,
24
- showPreviousTransaction: true,
25
- showStorageRebate: true,
26
- showOwner: true,
19
+ const response = await client.core.getObjects({
20
+ objectIds: [...gasObjectIds, ...inputObjectIds],
21
+ include: {
22
+ objectBcs: true,
27
23
  },
28
24
  });
29
25
 
30
- // NOTE: We should probably get rid of this manual serialization logic in favor of using the
31
- // already serialized object bytes from the GraphQL API once there is more mainstream support
32
- // for it + we can enforce the transport type on the Haneul client.
33
- const bcsObjects = objects
34
- .map((object) => {
35
- if (object.error || !object.data || object.data.bcs?.dataType !== 'moveObject') {
36
- return null;
37
- }
38
-
39
- return HaneulMoveObject.serialize({
40
- data: {
41
- MoveObject: {
42
- type: object.data.bcs.type,
43
- hasPublicTransfer: object.data.bcs.hasPublicTransfer,
44
- version: object.data.bcs.version,
45
- contents: object.data.bcs.bcsBytes,
46
- },
47
- },
48
- owner: object.data.owner!,
49
- previousTransaction: object.data.previousTransaction!,
50
- storageRebate: object.data.storageRebate!,
51
- }).toBytes();
52
- })
53
- .filter((bcsBytes): bcsBytes is Uint8Array<ArrayBuffer> => !!bcsBytes);
26
+ const bcsObjects = response.objects
27
+ .filter((obj): obj is Exclude<typeof obj, Error> => !(obj instanceof Error))
28
+ .map((object) => object.objectBcs)
29
+ .filter((bytes): bytes is Uint8Array<ArrayBuffer> => !!bytes);
54
30
 
55
31
  return { bcsObjects };
56
32
  };
@@ -1,8 +1,8 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { secp256r1 } from '@noble/curves/p256';
5
- import { secp256k1 } from '@noble/curves/secp256k1';
4
+ import { p256 as secp256r1 } from '@noble/curves/nist.js';
5
+ import { secp256k1 } from '@noble/curves/secp256k1.js';
6
6
  import { ASN1Construction, ASN1TagClass, DERElement } from 'asn1-ts';
7
7
 
8
8
  /** The total number of bits in the DER bit string for the uncompressed public key. */
@@ -70,14 +70,22 @@ export function getConcatenatedSignature(signature: Uint8Array, keyScheme: strin
70
70
  const [r, s] = derElement.toJSON() as [string, string];
71
71
 
72
72
  switch (keyScheme) {
73
- case 'Secp256k1':
74
- return new secp256k1.Signature(BigInt(r), BigInt(s))
75
- .normalizeS()
76
- .toCompactRawBytes() as Uint8Array<ArrayBuffer>;
77
- case 'Secp256r1':
78
- return new secp256r1.Signature(BigInt(r), BigInt(s))
79
- .normalizeS()
80
- .toCompactRawBytes() as Uint8Array<ArrayBuffer>;
73
+ case 'Secp256k1': {
74
+ const sig = new secp256k1.Signature(BigInt(r), BigInt(s));
75
+ const normalized = sig.hasHighS()
76
+ ? new secp256k1.Signature(sig.r, secp256k1.Point.Fn.neg(sig.s))
77
+ : sig;
78
+
79
+ return normalized.toBytes('compact') as Uint8Array<ArrayBuffer>;
80
+ }
81
+ case 'Secp256r1': {
82
+ const sig = new secp256r1.Signature(BigInt(r), BigInt(s));
83
+ const normalized = sig.hasHighS()
84
+ ? new secp256r1.Signature(sig.r, secp256r1.Point.Fn.neg(sig.s))
85
+ : sig;
86
+
87
+ return normalized.toBytes('compact') as Uint8Array<ArrayBuffer>;
88
+ }
81
89
  default:
82
90
  throw new Error('Unsupported key scheme');
83
91
  }
@@ -4,7 +4,7 @@
4
4
  import type { SignatureScheme } from '@haneullabs/haneul/cryptography';
5
5
  import { Signer } from '@haneullabs/haneul/cryptography';
6
6
  import { Secp256r1PublicKey } from '@haneullabs/haneul/keypairs/secp256r1';
7
- import { secp256r1 } from '@noble/curves/p256';
7
+ import { p256 as secp256r1 } from '@noble/curves/nist.js';
8
8
 
9
9
  // Convert from uncompressed (65 bytes) to compressed (33 bytes) format
10
10
  function getCompressedPublicKey(publicKey: Uint8Array) {
@@ -101,8 +101,11 @@ export class WebCryptoSigner extends Signer {
101
101
  bytes as BufferSource,
102
102
  );
103
103
 
104
- const signature = secp256r1.Signature.fromCompact(new Uint8Array(rawSignature));
104
+ const signature = secp256r1.Signature.fromBytes(new Uint8Array(rawSignature));
105
+ const normalizedSig = signature.hasHighS()
106
+ ? new secp256r1.Signature(signature.r, secp256r1.Point.Fn.neg(signature.s))
107
+ : signature;
105
108
 
106
- return signature.normalizeS().toCompactRawBytes() as Uint8Array<ArrayBuffer>;
109
+ return normalizedSig.toBytes('compact') as Uint8Array<ArrayBuffer>;
107
110
  }
108
111
  }
package/aws/package.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "private": true,
3
- "import": "../dist/esm/aws/index.js",
4
- "main": "../dist/cjs/aws/index.js",
5
- "sideEffects": false
6
- }
@@ -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,79 +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 aws_client_exports = {};
20
- __export(aws_client_exports, {
21
- AwsKmsClient: () => AwsKmsClient
22
- });
23
- module.exports = __toCommonJS(aws_client_exports);
24
- var import_secp256k1 = require("@haneullabs/haneul/keypairs/secp256k1");
25
- var import_secp256r1 = require("@haneullabs/haneul/keypairs/secp256r1");
26
- var import_utils = require("@haneullabs/haneul/utils");
27
- var import_utils2 = require("../utils/utils.js");
28
- var import_aws4fetch = require("./aws4fetch.js");
29
- class AwsKmsClient extends import_aws4fetch.AwsClient {
30
- constructor(options = {}) {
31
- if (!options.accessKeyId || !options.secretAccessKey) {
32
- throw new Error("AWS Access Key ID and Secret Access Key are required");
33
- }
34
- if (!options.region) {
35
- throw new Error("Region is required");
36
- }
37
- super({
38
- region: options.region,
39
- accessKeyId: options.accessKeyId,
40
- secretAccessKey: options.secretAccessKey,
41
- service: "kms",
42
- ...options
43
- });
44
- }
45
- async getPublicKey(keyId) {
46
- const publicKeyResponse = await this.runCommand("GetPublicKey", { KeyId: keyId });
47
- if (!publicKeyResponse.PublicKey) {
48
- throw new Error("Public Key not found for the supplied `keyId`");
49
- }
50
- const compressedKey = (0, import_utils2.publicKeyFromDER)((0, import_utils.fromBase64)(publicKeyResponse.PublicKey));
51
- switch (publicKeyResponse.KeySpec) {
52
- case "ECC_NIST_P256":
53
- return new import_secp256r1.Secp256r1PublicKey(compressedKey);
54
- case "ECC_SECG_P256K1":
55
- return new import_secp256k1.Secp256k1PublicKey(compressedKey);
56
- default:
57
- throw new Error("Unsupported key spec: " + publicKeyResponse.KeySpec);
58
- }
59
- }
60
- async runCommand(command, body, {
61
- region = this.region
62
- } = {}) {
63
- if (!region) {
64
- throw new Error("Region is required");
65
- }
66
- const res = await this.fetch(`https://kms.${region}.amazonaws.com/`, {
67
- headers: {
68
- "Content-Type": "application/x-amz-json-1.1",
69
- "X-Amz-Target": `TrentService.${command}`
70
- },
71
- body: JSON.stringify(body)
72
- });
73
- if (!res.ok) {
74
- throw new Error(await res.text());
75
- }
76
- return res.json();
77
- }
78
- }
79
- //# sourceMappingURL=aws-client.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/aws/aws-client.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Secp256k1PublicKey } from '@haneullabs/haneul/keypairs/secp256k1';\nimport { Secp256r1PublicKey } from '@haneullabs/haneul/keypairs/secp256r1';\nimport { fromBase64 } from '@haneullabs/haneul/utils';\n\nimport { publicKeyFromDER } from '../utils/utils.js';\nimport { AwsClient } from './aws4fetch.js';\n\ninterface KmsCommands {\n\tSign: {\n\t\trequest: {\n\t\t\tKeyId: string;\n\t\t\tMessage: string;\n\t\t\tMessageType: 'RAW' | 'DIGEST';\n\t\t\tSigningAlgorithm: 'ECDSA_SHA_256';\n\t\t};\n\t\tresponse: {\n\t\t\tKeyId: string;\n\t\t\tKeyOrigin: string;\n\t\t\tSignature: string;\n\t\t\tSigningAlgorithm: string;\n\t\t};\n\t};\n\tGetPublicKey: {\n\t\trequest: { KeyId: string };\n\t\tresponse: {\n\t\t\tCustomerMasterKeySpec: string;\n\t\t\tKeyId: string;\n\t\t\tKeyOrigin: string;\n\t\t\tKeySpec: string;\n\t\t\tKeyUsage: string;\n\t\t\tPublicKey: string;\n\t\t\tSigningAlgorithms: string[];\n\t\t};\n\t};\n}\n\nexport interface AwsClientOptions extends Partial<ConstructorParameters<typeof AwsClient>[0]> {}\n\nexport class AwsKmsClient extends AwsClient {\n\tconstructor(options: AwsClientOptions = {}) {\n\t\tif (!options.accessKeyId || !options.secretAccessKey) {\n\t\t\tthrow new Error('AWS Access Key ID and Secret Access Key are required');\n\t\t}\n\n\t\tif (!options.region) {\n\t\t\tthrow new Error('Region is required');\n\t\t}\n\n\t\tsuper({\n\t\t\tregion: options.region,\n\t\t\taccessKeyId: options.accessKeyId,\n\t\t\tsecretAccessKey: options.secretAccessKey,\n\t\t\tservice: 'kms',\n\t\t\t...options,\n\t\t});\n\t}\n\n\tasync getPublicKey(keyId: string) {\n\t\tconst publicKeyResponse = await this.runCommand('GetPublicKey', { KeyId: keyId });\n\n\t\tif (!publicKeyResponse.PublicKey) {\n\t\t\tthrow new Error('Public Key not found for the supplied `keyId`');\n\t\t}\n\n\t\tconst compressedKey = publicKeyFromDER(fromBase64(publicKeyResponse.PublicKey));\n\n\t\tswitch (publicKeyResponse.KeySpec) {\n\t\t\tcase 'ECC_NIST_P256':\n\t\t\t\treturn new Secp256r1PublicKey(compressedKey);\n\t\t\tcase 'ECC_SECG_P256K1':\n\t\t\t\treturn new Secp256k1PublicKey(compressedKey);\n\t\t\tdefault:\n\t\t\t\tthrow new Error('Unsupported key spec: ' + publicKeyResponse.KeySpec);\n\t\t}\n\t}\n\n\tasync runCommand<T extends keyof KmsCommands>(\n\t\tcommand: T,\n\t\tbody: KmsCommands[T]['request'],\n\t\t{\n\t\t\tregion = this.region!,\n\t\t}: {\n\t\t\tregion?: string;\n\t\t} = {},\n\t): Promise<KmsCommands[T]['response']> {\n\t\tif (!region) {\n\t\t\tthrow new Error('Region is required');\n\t\t}\n\n\t\tconst res = await this.fetch(`https://kms.${region}.amazonaws.com/`, {\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/x-amz-json-1.1',\n\t\t\t\t'X-Amz-Target': `TrentService.${command}`,\n\t\t\t},\n\t\t\tbody: JSON.stringify(body),\n\t\t});\n\n\t\tif (!res.ok) {\n\t\t\tthrow new Error(await res.text());\n\t\t}\n\n\t\treturn res.json();\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAmC;AACnC,uBAAmC;AACnC,mBAA2B;AAE3B,IAAAA,gBAAiC;AACjC,uBAA0B;AAiCnB,MAA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AAM,MAAM,IAAI,KAAK,CAAC;AAAA,IACjC;AAEA,WAAO,IAAI,KAAK;AAAA,EACjB;AACD;",
6
- "names": ["import_utils"]
7
- }
@@ -1,61 +0,0 @@
1
- import type { PublicKey } from '@haneullabs/haneul/cryptography';
2
- import { Signer } from '@haneullabs/haneul/cryptography';
3
- import type { AwsClientOptions } from './aws-client.js';
4
- import { AwsKmsClient } from './aws-client.js';
5
- /**
6
- * Configuration options for initializing the AwsKmsSigner.
7
- */
8
- export interface AwsKmsSignerOptions {
9
- /** AWS KMS Key ID used for signing */
10
- kmsKeyId: string;
11
- /** Options for setting up the AWS KMS client */
12
- client: AwsKmsClient;
13
- /** Public key */
14
- publicKey: PublicKey;
15
- }
16
- /**
17
- * Aws KMS Signer integrates AWS Key Management Service (KMS) with the Haneul blockchain
18
- * to provide signing capabilities using AWS-managed cryptographic keys.
19
- */
20
- export declare class AwsKmsSigner extends Signer {
21
- #private;
22
- /**
23
- * Creates an instance of AwsKmsSigner. It's expected to call the static `fromKeyId` method to create an instance.
24
- * For example:
25
- * ```
26
- * const signer = await AwsKmsSigner.fromKeyId(keyId, options);
27
- * ```
28
- * @throws Will throw an error if required AWS credentials or region are not provided.
29
- */
30
- constructor({ kmsKeyId, client, publicKey }: AwsKmsSignerOptions);
31
- /**
32
- * Retrieves the key scheme used by this signer.
33
- * @returns AWS supports only Secp256k1 and Secp256r1 schemes.
34
- */
35
- getKeyScheme(): "Secp256k1" | "Secp256r1" | "ED25519" | "MultiSig" | "ZkLogin" | "Passkey";
36
- /**
37
- * Retrieves the public key associated with this signer.
38
- * @returns The Secp256k1PublicKey instance.
39
- * @throws Will throw an error if the public key has not been initialized.
40
- */
41
- getPublicKey(): PublicKey;
42
- /**
43
- * Signs the given data using AWS KMS.
44
- * @param bytes - The data to be signed as a Uint8Array.
45
- * @returns A promise that resolves to the signature as a Uint8Array.
46
- * @throws Will throw an error if the public key is not initialized or if signing fails.
47
- */
48
- sign(bytes: Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
49
- /**
50
- * Synchronous signing is not supported by AWS KMS.
51
- * @throws Always throws an error indicating synchronous signing is unsupported.
52
- * @deprecated use `sign` instead
53
- */
54
- signData(): never;
55
- /**
56
- * Prepares the signer by fetching and setting the public key from AWS KMS.
57
- * It is recommended to initialize an `AwsKmsSigner` instance using this function.
58
- * @returns A promise that resolves once a `AwsKmsSigner` instance is prepared (public key is set).
59
- */
60
- static fromKeyId(keyId: string, options: AwsClientOptions): Promise<AwsKmsSigner>;
61
- }