@mysten/gcp-kms-signer 0.2.16 → 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/gcp-kms-client.d.mts +2 -1
- package/dist/gcp-kms-client.d.mts.map +1 -1
- package/dist/gcp-kms-client.mjs.map +1 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +7 -7
- package/src/gcp-kms-client.ts +8 -6
- package/src/utils.ts +4 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @mysten/gcp-kms-signer
|
|
2
2
|
|
|
3
|
+
## 0.2.18
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f2f7048: Upgrade workspace dependencies, remove the legacy dapp-kit package, and migrate the
|
|
8
|
+
remaining consumers to the current gRPC-based dapp-kit. Remove the legacy API reference while
|
|
9
|
+
retaining the migration guide and deprecation notice.
|
|
10
|
+
|
|
11
|
+
## 0.2.17
|
|
12
|
+
|
|
3
13
|
## 0.2.16
|
|
4
14
|
|
|
5
15
|
## 0.2.15
|
|
@@ -2,6 +2,7 @@ import { KeyManagementServiceClient } from "@google-cloud/kms";
|
|
|
2
2
|
import { PublicKey, Signer } from "@mysten/sui/cryptography";
|
|
3
3
|
|
|
4
4
|
//#region src/gcp-kms-client.d.ts
|
|
5
|
+
type GcpKmsClient = Pick<KeyManagementServiceClient, 'asymmetricSign' | 'cryptoKeyVersionPath' | 'getPublicKey'>;
|
|
5
6
|
/**
|
|
6
7
|
* Configuration options for initializing the GcpKmsSigner.
|
|
7
8
|
*/
|
|
@@ -9,7 +10,7 @@ interface GcpKmsSignerOptions {
|
|
|
9
10
|
/** The version name generated from `client.cryptoKeyVersionPath()` */
|
|
10
11
|
versionName: string;
|
|
11
12
|
/** Options for setting up the GCP KMS client */
|
|
12
|
-
client:
|
|
13
|
+
client: GcpKmsClient;
|
|
13
14
|
/** Public key */
|
|
14
15
|
publicKey: PublicKey;
|
|
15
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gcp-kms-client.d.mts","names":[],"sources":["../src/gcp-kms-client.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"gcp-kms-client.d.mts","names":[],"sources":["../src/gcp-kms-client.ts"],"mappings":";;;;KAWK,YAAA,GAAe,IAAA,CACnB,0BAAA;AAR2E;;;AAAA,UAe3D,mBAAA;EAPU;EAS1B,WAAA;EAFmC;EAInC,MAAA,EAAQ,YAAA;EAEY;EAApB,SAAA,EAAW,SAAA;AAAA;;;;;cAOC,YAAA,SAAqB,MAAA;EAAA;EAAR;;;;;;;;;;IAgBX,WAAA;IAAa,MAAA;IAAQ;EAAA,GAAa,mBAAA;EAgCjB;;;;EAnB/B,YAAA,CAAA;EA7BiC;;;;;EAsCjC,YAAA,CAAA,GAAY,SAAA;EAtBE;;;;;;EAgCR,IAAA,CAAK,KAAA,EAAO,UAAA,GAAa,OAAA,CAAQ,UAAA,CAAW,WAAA;EAnBlD;;;;;EAAA,OAqCa,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gcp-kms-client.mjs","names":["#client","#versionName","#publicKey"],"sources":["../src/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 '@mysten/sui/cryptography';\nimport { SIGNATURE_FLAG_TO_SCHEME, Signer } from '@mysten/sui/cryptography';\nimport { Secp256k1PublicKey } from '@mysten/sui/keypairs/secp256k1';\nimport { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';\nimport { fromBase64 } from '@mysten/sui/utils';\n\nimport { getConcatenatedSignature, publicKeyFromDER } from './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:
|
|
1
|
+
{"version":3,"file":"gcp-kms-client.mjs","names":["#client","#versionName","#publicKey"],"sources":["../src/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 '@mysten/sui/cryptography';\nimport { SIGNATURE_FLAG_TO_SCHEME, Signer } from '@mysten/sui/cryptography';\nimport { Secp256k1PublicKey } from '@mysten/sui/keypairs/secp256k1';\nimport { Secp256r1PublicKey } from '@mysten/sui/keypairs/secp256r1';\nimport { fromBase64 } from '@mysten/sui/utils';\n\nimport { getConcatenatedSignature, publicKeyFromDER } from './utils.js';\n\ntype GcpKmsClient = Pick<\n\tKeyManagementServiceClient,\n\t'asymmetricSign' | 'cryptoKeyVersionPath' | 'getPublicKey'\n>;\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: GcpKmsClient;\n\t/** Public key */\n\tpublicKey: PublicKey;\n}\n\n/**\n * GCP KMS Signer integrates GCP Key Management Service (KMS) with the Sui 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: GcpKmsClient;\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(client: GcpKmsClient, versionName: string): 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":";;;;;;;;;;;;AAgCA,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,aAAa,QAAsB,aAAyC;CAC1F,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"}
|
package/dist/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":["secp256r1"],"sources":["../src/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 (
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":["secp256r1"],"sources":["../src/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\tderElement.tagClass === ASN1TagClass.universal &&\n\t\tderElement.construction === ASN1Construction.constructed\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,KAAI,EACH,WAAW,aAAa,aAAa,aACrC,WAAW,iBAAiB,iBAAiB,aAE7C,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"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "Mysten Labs <build@mystenlabs.com>",
|
|
4
4
|
"description": "Sui signer using Google Cloud KMS",
|
|
5
5
|
"homepage": "https://sdk.mystenlabs.com",
|
|
6
|
-
"version": "0.2.
|
|
6
|
+
"version": "0.2.18",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"sideEffects": false,
|
|
@@ -35,18 +35,18 @@
|
|
|
35
35
|
"node": ">=22"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@google-cloud/kms": "^
|
|
39
|
-
"@noble/curves": "^2.
|
|
38
|
+
"@google-cloud/kms": "^6.0.0",
|
|
39
|
+
"@noble/curves": "^2.3.0",
|
|
40
40
|
"asn1-ts": "^11.1.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@mysten/sui": "^2.26.
|
|
43
|
+
"@mysten/sui": "^2.26.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@types/node": "^
|
|
46
|
+
"@types/node": "^26.2.0",
|
|
47
47
|
"dotenv": "^17.4.2",
|
|
48
|
-
"typescript": "^
|
|
49
|
-
"vitest": "^4.1.
|
|
48
|
+
"typescript": "^7.0.2",
|
|
49
|
+
"vitest": "^4.1.10"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|
package/src/gcp-kms-client.ts
CHANGED
|
@@ -9,6 +9,11 @@ import { fromBase64 } from '@mysten/sui/utils';
|
|
|
9
9
|
|
|
10
10
|
import { getConcatenatedSignature, publicKeyFromDER } from './utils.js';
|
|
11
11
|
|
|
12
|
+
type GcpKmsClient = Pick<
|
|
13
|
+
KeyManagementServiceClient,
|
|
14
|
+
'asymmetricSign' | 'cryptoKeyVersionPath' | 'getPublicKey'
|
|
15
|
+
>;
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
18
|
* Configuration options for initializing the GcpKmsSigner.
|
|
14
19
|
*/
|
|
@@ -16,7 +21,7 @@ export interface GcpKmsSignerOptions {
|
|
|
16
21
|
/** The version name generated from `client.cryptoKeyVersionPath()` */
|
|
17
22
|
versionName: string;
|
|
18
23
|
/** Options for setting up the GCP KMS client */
|
|
19
|
-
client:
|
|
24
|
+
client: GcpKmsClient;
|
|
20
25
|
/** Public key */
|
|
21
26
|
publicKey: PublicKey;
|
|
22
27
|
}
|
|
@@ -28,7 +33,7 @@ export interface GcpKmsSignerOptions {
|
|
|
28
33
|
export class GcpKmsSigner extends Signer {
|
|
29
34
|
#publicKey: PublicKey;
|
|
30
35
|
/** GCP KMS client instance */
|
|
31
|
-
#client:
|
|
36
|
+
#client: GcpKmsClient;
|
|
32
37
|
/** GCP KMS version name (generated from `client.cryptoKeyVersionPath()`) */
|
|
33
38
|
#versionName: string;
|
|
34
39
|
|
|
@@ -128,10 +133,7 @@ export class GcpKmsSigner extends Signer {
|
|
|
128
133
|
/**
|
|
129
134
|
* Retrieves the public key associated with the given version name.
|
|
130
135
|
*/
|
|
131
|
-
async function getPublicKey(
|
|
132
|
-
client: KeyManagementServiceClient,
|
|
133
|
-
versionName: string,
|
|
134
|
-
): Promise<PublicKey> {
|
|
136
|
+
async function getPublicKey(client: GcpKmsClient, versionName: string): Promise<PublicKey> {
|
|
135
137
|
const [publicKey] = await client.getPublicKey({ name: versionName });
|
|
136
138
|
|
|
137
139
|
const { algorithm, pem } = publicKey;
|
package/src/utils.ts
CHANGED
|
@@ -39,12 +39,10 @@ export function publicKeyFromDER(derBytes: Uint8Array) {
|
|
|
39
39
|
derElement.fromBytes(encodedData);
|
|
40
40
|
|
|
41
41
|
// Validate the ASN.1 structure of the public key
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
)
|
|
47
|
-
) {
|
|
42
|
+
if (!(
|
|
43
|
+
derElement.tagClass === ASN1TagClass.universal &&
|
|
44
|
+
derElement.construction === ASN1Construction.constructed
|
|
45
|
+
)) {
|
|
48
46
|
throw new Error('Unexpected ASN.1 structure');
|
|
49
47
|
}
|
|
50
48
|
|