Skip to content

Commit

Permalink
Merge pull request #7 from bugbytesinc/vnext-0.31.10
Browse files Browse the repository at this point in the history
Change ID generation in hapi-connect
  • Loading branch information
bugbytesinc authored Dec 29, 2022
2 parents 64557eb + e4169c8 commit c54ac7e
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 29 deletions.
6 changes: 3 additions & 3 deletions packages/hapi-connect/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
14 changes: 5 additions & 9 deletions packages/hapi-connect/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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));
}
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 3 additions & 7 deletions packages/hapi-connect/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -68,7 +64,7 @@ export class HashConnectClient {
accountToSign: string,
returnTransaction = false
): Promise<TransactionResponse> {
const id = crypto.randomUUID();
const id = createRandomId();
this.send(topic, "Transaction", {
id,
topic,
Expand Down Expand Up @@ -96,7 +92,7 @@ export class HashConnectClient {
network: string,
multiAccount: boolean
): Promise<AdditionalAccountResponse> {
const id = crypto.randomUUID();
const id = createRandomId();
this.send(topic, "AdditionalAccountRequest", {
id,
topic,
Expand Down
5 changes: 5 additions & 0 deletions packages/hapi-connect/src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as ed from '@noble/ed25519';

export function createRandomId() {
return ed.utils.bytesToHex(ed.utils.randomBytes(20));
}
6 changes: 3 additions & 3 deletions packages/hapi-mempool/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/hapi-mirror/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/hapi-proto/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/hapi-util/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion reference/hedera-protobufs
Submodule hedera-protobufs updated 108 files

0 comments on commit c54ac7e

Please sign in to comment.