From e4169c8b383985528aa765f71aa3784efca1c87d Mon Sep 17 00:00:00 2001 From: Jason Fabritz Date: Thu, 29 Dec 2022 12:54:08 -0500 Subject: [PATCH] Change ID generation in hapi-connect Changed the unique ID generation routine from the intrinsic randomUUID() method to one that utilizes the ed package (which is already a dependency of the connect package). Downstream projects are having random issues with relying on the intrinsic crypto instance. --- packages/hapi-connect/package.json | 6 +++--- packages/hapi-connect/src/cache.ts | 14 +++++--------- packages/hapi-connect/src/client.ts | 10 +++------- packages/hapi-connect/src/util.ts | 5 +++++ packages/hapi-mempool/package.json | 6 +++--- packages/hapi-mirror/package.json | 6 +++--- packages/hapi-proto/package.json | 2 +- packages/hapi-util/package.json | 4 ++-- reference/hedera-protobufs | 2 +- 9 files changed, 26 insertions(+), 29 deletions(-) create mode 100644 packages/hapi-connect/src/util.ts diff --git a/packages/hapi-connect/package.json b/packages/hapi-connect/package.json index 1220e4a..1df8487 100644 --- a/packages/hapi-connect/package.json +++ b/packages/hapi-connect/package.json @@ -1,6 +1,6 @@ { "name": "@bugbytes/hapi-connect", - "version": "0.31.9", + "version": "0.31.10", "description": "Lightweight HashConnect Browser Side Client Library", "main": "./lib/index.js", "exports": "./lib/index.js", @@ -25,8 +25,8 @@ }, "homepage": "https://github.com/bugbytesinc/hapi-proto#readme", "peerDependencies": { - "@bugbytes/hapi-proto": "0.31.9", - "@bugbytes/hapi-util": "0.31.9", + "@bugbytes/hapi-proto": "0.31.10", + "@bugbytes/hapi-util": "0.31.10", "long": ">=5.2.0", "protobufjs": ">=7.1.2", "simple-crypto-js": "^3.0.1", diff --git a/packages/hapi-connect/src/cache.ts b/packages/hapi-connect/src/cache.ts index d4a47af..c76d8b9 100644 --- a/packages/hapi-connect/src/cache.ts +++ b/packages/hapi-connect/src/cache.ts @@ -3,11 +3,7 @@ import { type TransactionResponse } from "./transaction-response"; import { ConnectionInfo } from "./connection-info"; import { PairRequest } from "./pair-request"; import type { KnownNetwork } from "./wallet-metadata"; -declare global { - interface Crypto { - randomUUID: () => string; - } -} +import { createRandomId } from "./util"; export const DEFAULT_CACHE_KEY = "hashconnect.data"; @@ -21,8 +17,8 @@ export class HashConnectCachedClient { const value = localStorage.getItem(cacheKey); const connection = !!value ? JSON.parse(value) as ConnectionInfo : {} as ConnectionInfo; if (!connection.topic || !connection.secret || !connection.pairedWallet) { - connection.topic = crypto.randomUUID(); - connection.secret = crypto.randomUUID(); + connection.topic = createRandomId(); + connection.secret = createRandomId(); connection.pairedWallet = undefined; localStorage.setItem(cacheKey, JSON.stringify(connection)); } @@ -58,8 +54,8 @@ export class HashConnectCachedClient { closeWallet(): void { if (this._connection.pairedWallet) { - this._connection.topic = crypto.randomUUID(); - this._connection.secret = crypto.randomUUID(); + this._connection.topic = createRandomId(); + this._connection.secret = createRandomId(); this._connection.pairedWallet = undefined; localStorage?.setItem(this._cacheKey, JSON.stringify(this._connection)); this._client = new HashConnectClient(); diff --git a/packages/hapi-connect/src/client.ts b/packages/hapi-connect/src/client.ts index 8bfb611..249809d 100644 --- a/packages/hapi-connect/src/client.ts +++ b/packages/hapi-connect/src/client.ts @@ -5,12 +5,8 @@ import { Relay } from "./relay"; import { RelayMessage } from "./relay-message"; import { TransactionResponse } from "./transaction-response"; import { AdditionalAccountResponse } from "./additional-account-response"; +import { createRandomId } from "./util"; -declare global { - interface Crypto { - randomUUID: () => string; - } -} declare type Handler = (value: RelayMessage) => boolean; export class HashConnectClient { @@ -68,7 +64,7 @@ export class HashConnectClient { accountToSign: string, returnTransaction = false ): Promise { - const id = crypto.randomUUID(); + const id = createRandomId(); this.send(topic, "Transaction", { id, topic, @@ -96,7 +92,7 @@ export class HashConnectClient { network: string, multiAccount: boolean ): Promise { - const id = crypto.randomUUID(); + const id = createRandomId(); this.send(topic, "AdditionalAccountRequest", { id, topic, diff --git a/packages/hapi-connect/src/util.ts b/packages/hapi-connect/src/util.ts new file mode 100644 index 0000000..7a65eb8 --- /dev/null +++ b/packages/hapi-connect/src/util.ts @@ -0,0 +1,5 @@ +import * as ed from '@noble/ed25519'; + +export function createRandomId() { + return ed.utils.bytesToHex(ed.utils.randomBytes(20)); +} \ No newline at end of file diff --git a/packages/hapi-mempool/package.json b/packages/hapi-mempool/package.json index eab473b..9df1a99 100644 --- a/packages/hapi-mempool/package.json +++ b/packages/hapi-mempool/package.json @@ -1,6 +1,6 @@ { "name": "@bugbytes/hapi-mempool", - "version": "0.31.9", + "version": "0.31.10", "description": "Hedera Mempool Client", "main": "./lib/index.js", "exports": "./lib/index.js", @@ -24,8 +24,8 @@ }, "homepage": "https://github.com/bugbytesinc/hapi-proto#readme", "peerDependencies": { - "@bugbytes/hapi-proto": "0.31.9", - "@bugbytes/hapi-util": "0.31.9", + "@bugbytes/hapi-proto": "0.31.10", + "@bugbytes/hapi-util": "0.31.10", "long": ">=5.2.0", "protobufjs": ">=7.1.2" } diff --git a/packages/hapi-mirror/package.json b/packages/hapi-mirror/package.json index f6cd0fd..be9a1aa 100644 --- a/packages/hapi-mirror/package.json +++ b/packages/hapi-mirror/package.json @@ -1,6 +1,6 @@ { "name": "@bugbytes/hapi-mirror", - "version": "0.31.9", + "version": "0.31.10", "description": "Hedera Mirror Node Client", "main": "./lib/index.js", "exports": "./lib/index.js", @@ -24,8 +24,8 @@ }, "homepage": "https://github.com/bugbytesinc/hapi-proto#readme", "peerDependencies": { - "@bugbytes/hapi-proto": "0.31.9", - "@bugbytes/hapi-util": "0.31.9", + "@bugbytes/hapi-proto": "0.31.10", + "@bugbytes/hapi-util": "0.31.10", "long": ">=5.2.0", "protobufjs": ">=7.1.2" } diff --git a/packages/hapi-proto/package.json b/packages/hapi-proto/package.json index b3c4d12..db0db77 100644 --- a/packages/hapi-proto/package.json +++ b/packages/hapi-proto/package.json @@ -1,6 +1,6 @@ { "name": "@bugbytes/hapi-proto", - "version": "0.31.9", + "version": "0.31.10", "description": "Hedera API Protobuf Typescript/Javascript Bindings", "main": "./lib/index.js", "exports": "./lib/index.js", diff --git a/packages/hapi-util/package.json b/packages/hapi-util/package.json index 7bccd13..6447764 100644 --- a/packages/hapi-util/package.json +++ b/packages/hapi-util/package.json @@ -1,6 +1,6 @@ { "name": "@bugbytes/hapi-util", - "version": "0.31.9", + "version": "0.31.10", "description": "Hedera API Protobuf Typescript/Javascript Utilities", "main": "./lib/index.js", "exports": "./lib/index.js", @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/bugbytesinc/hapi-proto#readme", "peerDependencies": { - "@bugbytes/hapi-proto": "0.31.9", + "@bugbytes/hapi-proto": "0.31.10", "@noble/ed25519": "^1.7.1", "@noble/secp256k1": "^1.7.0", "long": ">=5.2.0", diff --git a/reference/hedera-protobufs b/reference/hedera-protobufs index 6c3e6d3..ba840e5 160000 --- a/reference/hedera-protobufs +++ b/reference/hedera-protobufs @@ -1 +1 @@ -Subproject commit 6c3e6d37d9652bdb57600587d0218c9245eb513e +Subproject commit ba840e5d37afd9f5b8283b862519587319bf994a