diff --git a/example/package-lock.json b/example/package-lock.json index 192d779..a62a82d 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@mantine/core": "^7.11.2", "@mantine/hooks": "^7.11.2", + "@sats-connect/core": "^0.4.2-5220ac4", "@stacks/common": "^7.0.2", "@stacks/stacking": "^7.0.2", "@stacks/transactions": "^7.0.2", @@ -1416,6 +1417,41 @@ "win32" ] }, + "node_modules/@sats-connect/core": { + "version": "0.4.2-5220ac4", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.4.2-5220ac4.tgz", + "integrity": "sha512-iwrWagHyg2UOjH9SAQHeALyMMmvqd8lLkdiv+PeW0jn+wKRY75DqcmDvq1GTqILd7ZaeDp3Gf/czFTf6woeSbA==", + "dependencies": { + "axios": "1.7.7", + "bitcoin-address-validation": "2.2.3", + "buffer": "6.0.3", + "jsontokens": "4.0.1", + "valibot": "0.42.1" + } + }, + "node_modules/@sats-connect/core/node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, "node_modules/@scure/base": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.1.tgz", @@ -2095,6 +2131,11 @@ "util": "^0.12.5" } }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, "node_modules/available-typed-arrays": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", @@ -2109,6 +2150,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -2119,6 +2170,14 @@ "resolved": "https://registry.npmjs.org/base-x/-/base-x-4.0.0.tgz", "integrity": "sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw==" }, + "node_modules/base58-js": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/base58-js/-/base58-js-1.0.5.tgz", + "integrity": "sha512-LkkAPP8Zu+c0SVNRTRVDyMfKVORThX+rCViget00xdgLRrKkClCTz1T7cIrpr69ShwV5XJuuoZvMvJ43yURwkA==", + "engines": { + "node": ">= 8" + } + }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", @@ -2181,6 +2240,16 @@ "safe-buffer": "^5.0.1" } }, + "node_modules/bitcoin-address-validation": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/bitcoin-address-validation/-/bitcoin-address-validation-2.2.3.tgz", + "integrity": "sha512-1uGCGl26Ye8JG5qcExtFLQfuib6qEZWNDo1ZlLlwp/z7ygUFby3IxolgEfgMGaC+LG9csbVASLcH8fRLv7DIOg==", + "dependencies": { + "base58-js": "^1.0.0", + "bech32": "^2.0.0", + "sha256-uint8array": "^0.10.3" + } + }, "node_modules/bitcoinjs-lib": { "version": "6.1.6", "resolved": "https://registry.npmjs.org/bitcoinjs-lib/-/bitcoinjs-lib-6.1.6.tgz", @@ -2701,6 +2770,17 @@ "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2950,6 +3030,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/des.js": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.1.0.tgz", @@ -3751,6 +3839,25 @@ "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.1.tgz", "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==" }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -3759,6 +3866,19 @@ "is-callable": "^1.1.3" } }, + "node_modules/form-data": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -4090,7 +4210,6 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", - "dev": true, "funding": [ { "type": "github", @@ -4615,6 +4734,16 @@ "node": ">=6" } }, + "node_modules/jsontokens": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jsontokens/-/jsontokens-4.0.1.tgz", + "integrity": "sha512-+MO415LEN6M+3FGsRz4wU20g7N2JA+2j9d9+pGaNJHviG4L8N0qzavGyENw6fJqsq9CcrHOIL6iWX5yeTZ86+Q==", + "dependencies": { + "@noble/hashes": "^1.1.2", + "@noble/secp256k1": "^1.6.3", + "base64-js": "^1.5.1" + } + }, "node_modules/jsx-ast-utils": { "version": "3.3.5", "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-3.3.5.tgz", @@ -4747,6 +4876,25 @@ "miller-rabin": "bin/miller-rabin" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimalistic-assert": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", @@ -5421,6 +5569,11 @@ "react-is": "^16.13.1" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/public-encrypt": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/public-encrypt/-/public-encrypt-4.0.3.tgz", @@ -5981,6 +6134,11 @@ "sha.js": "bin.js" } }, + "node_modules/sha256-uint8array": { + "version": "0.10.7", + "resolved": "https://registry.npmjs.org/sha256-uint8array/-/sha256-uint8array-0.10.7.tgz", + "integrity": "sha512-1Q6JQU4tX9NqsDGodej6pkrUVQVNapLZnvkwIhddH/JqzBZF1fSaxSWNY6sziXBE8aEa2twtGkXUrwzGeZCMpQ==" + }, "node_modules/shallowequal": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/shallowequal/-/shallowequal-1.1.0.tgz", @@ -6431,7 +6589,7 @@ "version": "5.5.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", - "dev": true, + "devOptional": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -6612,6 +6770,19 @@ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, + "node_modules/valibot": { + "version": "0.42.1", + "resolved": "https://registry.npmjs.org/valibot/-/valibot-0.42.1.tgz", + "integrity": "sha512-3keXV29Ar5b//Hqi4MbSdV7lfVp6zuYLZuA9V1PvQUsXqogr+u5lvLPLk3A4f74VUXDnf/JfWMN6sB+koJ/FFw==", + "peerDependencies": { + "typescript": ">=5" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/varuint-bitcoin": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/varuint-bitcoin/-/varuint-bitcoin-1.1.2.tgz", diff --git a/example/src/components/stacks/SignTransactions/mutationFunction.ts b/example/src/components/stacks/SignTransactions/mutationFunction.ts index d35d5a7..7c2188e 100644 --- a/example/src/components/stacks/SignTransactions/mutationFunction.ts +++ b/example/src/components/stacks/SignTransactions/mutationFunction.ts @@ -6,6 +6,7 @@ import { makeUnsignedContractDeploy, makeUnsignedSTXTokenTransfer, noneCV, + StacksTransactionWire, standardPrincipalCV, uintCV, } from '@stacks/transactions'; @@ -40,6 +41,14 @@ export interface MutationFnArgs { publicKey: string; } +function getLastUsedNonce(transactions: StacksTransactionWire[]) { + const lastTransaction = transactions.at(-1); + + if (!lastTransaction) return undefined; + + return lastTransaction.auth.spendingCondition.nonce + 1n; +} + export async function mutationFunction({ isPoolAllowContractSelected, isPoolDelegateStacksSelected, @@ -48,7 +57,7 @@ export async function mutationFunction({ broadcast, publicKey, }: MutationFnArgs) { - const transactions: string[] = []; + const transactions: StacksTransactionWire[] = []; if (isPoolAllowContractSelected) { const transaction = await makeUnsignedContractCall({ @@ -57,8 +66,9 @@ export async function mutationFunction({ functionName: 'allow-contract-caller', functionArgs: [contractPrincipalCV(poolContractAddress, poolContractName), noneCV()], publicKey, + ...(getLastUsedNonce(transactions) && { nonce: getLastUsedNonce(transactions) }), }); - transactions.push(transaction.serialize()); + transactions.push(transaction); } if (isPoolDelegateStacksSelected) { @@ -67,7 +77,7 @@ export async function mutationFunction({ contractName: poolContractName, functionName: 'delegate-stx', functionArgs: [ - uintCV(1234567890), + uintCV(101_000_000), standardPrincipalCV(poolAdminStacksAddress), noneCV(), noneCV(), @@ -75,8 +85,9 @@ export async function mutationFunction({ noneCV(), ], publicKey, + ...(getLastUsedNonce(transactions) && { nonce: getLastUsedNonce(transactions) }), }); - transactions.push(transaction.serialize()); + transactions.push(transaction); } if (isContractDeploySelected) { @@ -85,8 +96,9 @@ export async function mutationFunction({ contractName: `hello-world-${now}`, codeBody: helloWorldContractBody, publicKey, + ...(getLastUsedNonce(transactions) && { nonce: getLastUsedNonce(transactions) }), }); - transactions.push(transaction.serialize()); + transactions.push(transaction); } if (isTokenTransferSelected) { @@ -94,12 +106,13 @@ export async function mutationFunction({ recipient: 'SP1VYV2JBF1QPNDSKHBZRAWRC4KQXP8ZSSRNKPJE4', // acc 4 amount: '100000', // 0.1 STX publicKey, + ...(getLastUsedNonce(transactions) && { nonce: getLastUsedNonce(transactions) }), }); - transactions.push(transaction.serialize()); + transactions.push(transaction); } const res = await request('stx_signTransactions', { - transactions, + transactions: transactions.map((t) => t.serialize()), broadcast, }); diff --git a/package-lock.json b/package-lock.json index 62c58f5..eaa6f20 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.0.1", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.4.1", + "@sats-connect/core": "^0.4.2-5220ac4", "@sats-connect/make-default-provider-config": "0.0.10", "@sats-connect/ui": "0.0.7" }, @@ -1716,9 +1716,9 @@ ] }, "node_modules/@sats-connect/core": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.4.1.tgz", - "integrity": "sha512-//0ge/FbKQZdhfFBR7LKdJxpzVB+bGfqHwkjHl0EX3QwvAu8n0dSoUZlym43+KB7gy0rgv1+ECFrOCeYGpGFgA==", + "version": "0.4.2-5220ac4", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.4.2-5220ac4.tgz", + "integrity": "sha512-iwrWagHyg2UOjH9SAQHeALyMMmvqd8lLkdiv+PeW0jn+wKRY75DqcmDvq1GTqILd7ZaeDp3Gf/czFTf6woeSbA==", "dependencies": { "axios": "1.7.7", "bitcoin-address-validation": "2.2.3", diff --git a/package.json b/package.json index 74a862a..4bae960 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ ] }, "dependencies": { - "@sats-connect/core": "0.4.1", + "@sats-connect/core": "^0.4.2-5220ac4", "@sats-connect/make-default-provider-config": "0.0.10", "@sats-connect/ui": "0.0.7" },