diff --git a/package-lock.json b/package-lock.json index 3ea3ef36b..7e45b3aef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19719,7 +19719,8 @@ "@onflow/util-logger": "^1.2.1", "@onflow/util-template": "^1.1.0", "deepmerge": "^4.2.2", - "sha3": "^2.1.4" + "sha3": "^2.1.4", + "uuid": "^9.0.1" }, "devDependencies": { "@onflow/fcl-bundle": "^1.3.1", @@ -19798,6 +19799,18 @@ "node": ">=4.2.0" } }, + "packages/sdk/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "bin": { + "uuid": "dist/bin/uuid" + } + }, "packages/transport-grpc": { "name": "@onflow/transport-grpc", "version": "1.2.2-accounts.0", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index fc179268c..3c276e47d 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -51,6 +51,7 @@ "@onflow/util-logger": "^1.2.1", "@onflow/util-template": "^1.1.0", "deepmerge": "^4.2.2", - "sha3": "^2.1.4" + "sha3": "^2.1.4", + "uuid": "^9.0.1" } } diff --git a/packages/sdk/src/interaction/interaction.js b/packages/sdk/src/interaction/interaction.js index 8dca33b36..703ba18f6 100644 --- a/packages/sdk/src/interaction/interaction.js +++ b/packages/sdk/src/interaction/interaction.js @@ -1,4 +1,5 @@ import {invariant} from "@onflow/util-invariant" +import {v4 as uuidv4} from "uuid" export const UNKNOWN /* */ = "UNKNOWN" export const SCRIPT /* */ = "SCRIPT" @@ -108,9 +109,6 @@ const KEYS = new Set(Object.keys(JSON.parse(IX))) export const interaction = () => JSON.parse(IX) -const CHARS = "abcdefghijklmnopqrstuvwxyz0123456789".split("") -const randChar = () => CHARS[~~(Math.random() * CHARS.length)] -export const uuid = () => Array.from({length: 10}, randChar).join("") export const isNumber = d => typeof d === "number" export const isArray = d => Array.isArray(d) export const isObj = d => d !== null && typeof d === "object" @@ -158,7 +156,7 @@ export const prepAccount = (acct, opts = {}) => ix => { const ACCOUNT = JSON.parse(ACCT) const role = opts.role - const tempId = uuid() + const tempId = uuidv4() if (acct.authorization && isFn(acct.authorization)) acct = {resolve: acct.authorization} @@ -196,7 +194,7 @@ export const prepAccount = (acct, opts = {}) => ix => { } export const makeArgument = arg => ix => { - let tempId = uuid() + let tempId = uuidv4() ix.message.arguments.push(tempId) ix.arguments[tempId] = JSON.parse(ARG) diff --git a/packages/sdk/src/resolve/resolve-accounts.js b/packages/sdk/src/resolve/resolve-accounts.js index 3ad4d00bb..8376d8e55 100644 --- a/packages/sdk/src/resolve/resolve-accounts.js +++ b/packages/sdk/src/resolve/resolve-accounts.js @@ -3,13 +3,10 @@ import {invariant} from "@onflow/util-invariant" import {log} from "@onflow/util-logger" import {isTransaction} from "../interaction/interaction.js" import {createSignableVoucher} from "./voucher.js" +import {v4 as uuidv4} from "uuid" const MAX_DEPTH_LIMIT = 5 -const CHARS = "abcdefghijklmnopqrstuvwxyz0123456789".split("") -const randChar = () => CHARS[~~(Math.random() * CHARS.length)] -const uuid = () => Array.from({length: 10}, randChar).join("") - const idof = acct => `${withPrefix(acct.addr)}-${acct.keyId}` const isFn = v => v && @@ -99,7 +96,7 @@ function addAccountToIx(ix, newAccount) { ) { newAccount.tempId = idof(newAccount) } else { - newAccount.tempId = newAccount.tempId || uuid() + newAccount.tempId = newAccount.tempId || uuidv4() } const existingAccount = ix.accounts[newAccount.tempId] || newAccount