@secondlayer/stacks 3.3.1 → 4.0.0

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.
Files changed (61) hide show
  1. package/dist/shared/{stacks-6bgh2c9h.js → stacks-27fmgajb.js} +11 -3
  2. package/dist/shared/{stacks-b221qkst.cjs.map → stacks-27fmgajb.js.map} +4 -3
  3. package/dist/shared/{stacks-jknrzd6v.js → stacks-2evvn48s.js} +2 -2
  4. package/dist/shared/{stacks-s361pmzs.cjs → stacks-90jcxs98.js} +84 -2
  5. package/dist/shared/{stacks-9d2d0qjc.js.map → stacks-90jcxs98.js.map} +6 -4
  6. package/dist/shared/{stacks-8e5atbps.cjs → stacks-dr5en54r.cjs} +9 -2
  7. package/dist/shared/{stacks-8e5atbps.cjs.map → stacks-dr5en54r.cjs.map} +2 -2
  8. package/dist/shared/{stacks-bm49tsh0.js → stacks-fse1f76h.js} +2 -3
  9. package/dist/shared/{stacks-bm49tsh0.js.map → stacks-fse1f76h.js.map} +1 -1
  10. package/dist/shared/{stacks-b221qkst.cjs → stacks-nyaw1z2a.cjs} +7 -2
  11. package/dist/shared/{stacks-6bgh2c9h.js.map → stacks-nyaw1z2a.cjs.map} +4 -3
  12. package/dist/shared/{stacks-9d2d0qjc.js → stacks-tdsp5gsb.cjs} +54 -23
  13. package/dist/shared/{stacks-s361pmzs.cjs.map → stacks-tdsp5gsb.cjs.map} +6 -4
  14. package/dist/shared/{stacks-r1m1r72q.js → stacks-thkhfwz8.js} +35 -5
  15. package/dist/shared/{stacks-r1m1r72q.js.map → stacks-thkhfwz8.js.map} +4 -3
  16. package/dist/shared/{stacks-v1hzk599.js → stacks-z3vztaz1.js} +7 -9
  17. package/dist/shared/{stacks-v1hzk599.js.map → stacks-z3vztaz1.js.map} +2 -2
  18. package/dist/shared/{stacks-fvnxj77s.cjs → stacks-zwgsbbb2.cjs} +28 -2
  19. package/dist/shared/{stacks-fvnxj77s.cjs.map → stacks-zwgsbbb2.cjs.map} +4 -3
  20. package/dist/src/actions/index.js +18 -23
  21. package/dist/src/actions/index.js.map +1 -1
  22. package/dist/src/bitcoin/index.js +3 -5
  23. package/dist/src/bitcoin/index.js.map +2 -2
  24. package/dist/src/bns/index.js +5 -8
  25. package/dist/src/bns/index.js.map +2 -2
  26. package/dist/src/index.js +19 -25
  27. package/dist/src/index.js.map +2 -2
  28. package/dist/src/postconditions/index.js +2 -3
  29. package/dist/src/postconditions/index.js.map +1 -1
  30. package/dist/src/pox/index.js +5 -8
  31. package/dist/src/pox/index.js.map +2 -2
  32. package/dist/src/pox5/index.js +5 -7
  33. package/dist/src/pox5/index.js.map +2 -2
  34. package/dist/src/sbtc/index.js +4 -6
  35. package/dist/src/sbtc/index.js.map +2 -2
  36. package/dist/src/stackingdao/index.js +5 -8
  37. package/dist/src/stackingdao/index.js.map +2 -2
  38. package/package.json +1 -6
  39. package/dist/shared/stacks-1mpmzzyp.js +0 -85
  40. package/dist/shared/stacks-1mpmzzyp.js.map +0 -11
  41. package/dist/shared/stacks-44y18a8e.cjs +0 -28
  42. package/dist/shared/stacks-44y18a8e.cjs.map +0 -10
  43. package/dist/shared/stacks-8khy9v27.cjs +0 -7
  44. package/dist/shared/stacks-8khy9v27.cjs.map +0 -10
  45. package/dist/shared/stacks-d6pgp4qk.cjs +0 -9
  46. package/dist/shared/stacks-d6pgp4qk.cjs.map +0 -9
  47. package/dist/shared/stacks-fh48neva.js +0 -13
  48. package/dist/shared/stacks-fh48neva.js.map +0 -10
  49. package/dist/shared/stacks-fjrpnkt3.cjs +0 -55
  50. package/dist/shared/stacks-fjrpnkt3.cjs.map +0 -11
  51. package/dist/shared/stacks-w8tt1fmt.js +0 -44
  52. package/dist/shared/stacks-w8tt1fmt.js.map +0 -10
  53. package/dist/shared/stacks-z53fwfcm.js +0 -3
  54. package/dist/shared/stacks-z53fwfcm.js.map +0 -9
  55. package/dist/src/x402/index.cjs +0 -65
  56. package/dist/src/x402/index.cjs.map +0 -11
  57. package/dist/src/x402/index.d.cts +0 -501
  58. package/dist/src/x402/index.d.ts +0 -501
  59. package/dist/src/x402/index.js +0 -90
  60. package/dist/src/x402/index.js.map +0 -11
  61. /package/dist/shared/{stacks-jknrzd6v.js.map → stacks-2evvn48s.js.map} +0 -0
@@ -1,28 +0,0 @@
1
- // src/actions/wallet/sponsorTransaction.ts
2
- async function sponsorTransaction(client, params) {
3
- const { transaction } = params;
4
- if (transaction.auth.authType !== AuthType.Sponsored) {
5
- throw new Error("Transaction must have sponsored authorization");
6
- }
7
- const account = client.account;
8
- if (!account)
9
- throw new Error("Account required");
10
- if (isProviderAccount(account)) {
11
- throw new Error("Provider accounts cannot sponsor transactions");
12
- }
13
- const nonce = params.nonce != null ? intToBigInt(params.nonce) : await resolveNonce(client, account.address);
14
- const fee = await resolveFee(client, transaction, params.fee);
15
- const sponsorCondition = createSingleSigSpendingCondition(account.publicKey, nonce, fee);
16
- const auth = transaction.auth;
17
- const sponsored = {
18
- ...transaction,
19
- auth: {
20
- ...auth,
21
- sponsorSpendingCondition: sponsorCondition
22
- }
23
- };
24
- return signSponsorWithAccount(sponsored, account);
25
- }
26
-
27
- //# debugId=2C7F1B8FDFB94A5364756E2164756E21
28
- //# sourceMappingURL=stacks-44y18a8e.cjs.map
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/actions/wallet/sponsorTransaction.ts"],
4
- "sourcesContent": [
5
- "import type { Client } from \"../../clients/types.ts\";\nimport { createSingleSigSpendingCondition } from \"../../transactions/authorization.ts\";\nimport { signSponsorWithAccount } from \"../../transactions/signer.ts\";\nimport {\n\tAuthType,\n\ttype SponsoredAuthorization,\n\ttype StacksTransaction,\n} from \"../../transactions/types.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { intToBigInt } from \"../../utils/encoding.ts\";\nimport { resolveNonce } from \"./nonceManager.ts\";\nimport { type FeeParam, isProviderAccount, resolveFee } from \"./utils.ts\";\n\nexport type SponsorTransactionParams = {\n\ttransaction: StacksTransaction;\n\tfee?: FeeParam;\n\tnonce?: IntegerType;\n};\n\n/** Sponsor a transaction: set sponsor spending condition, sign as sponsor */\nexport async function sponsorTransaction(\n\tclient: Client,\n\tparams: SponsorTransactionParams,\n): Promise<StacksTransaction> {\n\tconst { transaction } = params;\n\n\tif (transaction.auth.authType !== AuthType.Sponsored) {\n\t\tthrow new Error(\"Transaction must have sponsored authorization\");\n\t}\n\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\tif (isProviderAccount(account)) {\n\t\tthrow new Error(\"Provider accounts cannot sponsor transactions\");\n\t}\n\n\t// Resolve sponsor nonce\n\tconst nonce =\n\t\tparams.nonce != null\n\t\t\t? intToBigInt(params.nonce)\n\t\t\t: await resolveNonce(client, account.address);\n\n\t// Resolve sponsor fee. Estimation failure falls back to the minimum relay\n\t// fee instead of 0 (a 0-fee tx would be rejected at broadcast).\n\tconst fee = await resolveFee(client, transaction, params.fee);\n\n\t// Create sponsor spending condition\n\tconst sponsorCondition = createSingleSigSpendingCondition(\n\t\taccount.publicKey,\n\t\tnonce,\n\t\tfee,\n\t);\n\n\t// Set sponsor spending condition on the tx\n\tconst auth = transaction.auth as SponsoredAuthorization;\n\tconst sponsored: StacksTransaction = {\n\t\t...transaction,\n\t\tauth: {\n\t\t\t...auth,\n\t\t\tsponsorSpendingCondition: sponsorCondition,\n\t\t},\n\t};\n\n\t// Sign as sponsor\n\treturn signSponsorWithAccount(sponsored, account);\n}\n"
6
- ],
7
- "mappings": ";AAoBA,eAAsB,kBAAkB,CACvC,QACA,QAC6B;AAAA,EAC7B,QAAQ,gBAAgB;AAAA,EAExB,IAAI,YAAY,KAAK,aAAa,SAAS,WAAW;AAAA,IACrD,MAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AAAA,EAEA,MAAM,UAAU,OAAO;AAAA,EACvB,IAAI,CAAC;AAAA,IAAS,MAAM,IAAI,MAAM,kBAAkB;AAAA,EAChD,IAAI,kBAAkB,OAAO,GAAG;AAAA,IAC/B,MAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AAAA,EAGA,MAAM,QACL,OAAO,SAAS,OACb,YAAY,OAAO,KAAK,IACxB,MAAM,aAAa,QAAQ,QAAQ,OAAO;AAAA,EAI9C,MAAM,MAAM,MAAM,WAAW,QAAQ,aAAa,OAAO,GAAG;AAAA,EAG5D,MAAM,mBAAmB,iCACxB,QAAQ,WACR,OACA,GACD;AAAA,EAGA,MAAM,OAAO,YAAY;AAAA,EACzB,MAAM,YAA+B;AAAA,OACjC;AAAA,IACH,MAAM;AAAA,SACF;AAAA,MACH,0BAA0B;AAAA,IAC3B;AAAA,EACD;AAAA,EAGA,OAAO,uBAAuB,WAAW,OAAO;AAAA;",
8
- "debugId": "2C7F1B8FDFB94A5364756E2164756E21",
9
- "names": []
10
- }
@@ -1,7 +0,0 @@
1
- // src/errors/response.ts
2
- class MalformedResponseError extends BaseError {
3
- name = "MalformedResponseError";
4
- }
5
-
6
- //# debugId=31C375B5C92A878E64756E2164756E21
7
- //# sourceMappingURL=stacks-8khy9v27.cjs.map
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/errors/response.ts"],
4
- "sourcesContent": [
5
- "import { BaseError } from \"./base.ts\";\n\n/** Thrown when a node/API response is missing an expected field. */\nexport class MalformedResponseError extends BaseError {\n\toverride name = \"MalformedResponseError\";\n}\n"
6
- ],
7
- "mappings": ";AAGO,MAAM,+BAA+B,UAAU;AAAA,EAC5C,OAAO;AACjB;",
8
- "debugId": "31C375B5C92A878E64756E2164756E21",
9
- "names": []
10
- }
@@ -1,9 +0,0 @@
1
- // src/postconditions/index.ts
2
- var exports_postconditions = {};
3
- __export(exports_postconditions, {
4
- Pc: () => Pc
5
- });
6
- module.exports = __toCommonJS(exports_postconditions);
7
-
8
- //# debugId=826C758A4223AE2664756E2164756E21
9
- //# sourceMappingURL=stacks-d6pgp4qk.cjs.map
@@ -1,9 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [
5
- ],
6
- "mappings": "",
7
- "debugId": "826C758A4223AE2664756E2164756E21",
8
- "names": []
9
- }
@@ -1,13 +0,0 @@
1
- import {
2
- BaseError
3
- } from "./stacks-709tra19.js";
4
-
5
- // src/errors/response.ts
6
- class MalformedResponseError extends BaseError {
7
- name = "MalformedResponseError";
8
- }
9
-
10
- export { MalformedResponseError };
11
-
12
- //# debugId=93346D5AC0126F7F64756E2164756E21
13
- //# sourceMappingURL=stacks-fh48neva.js.map
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/errors/response.ts"],
4
- "sourcesContent": [
5
- "import { BaseError } from \"./base.ts\";\n\n/** Thrown when a node/API response is missing an expected field. */\nexport class MalformedResponseError extends BaseError {\n\toverride name = \"MalformedResponseError\";\n}\n"
6
- ],
7
- "mappings": ";;;;;AAGO,MAAM,+BAA+B,UAAU;AAAA,EAC5C,OAAO;AACjB;",
8
- "debugId": "93346D5AC0126F7F64756E2164756E21",
9
- "names": []
10
- }
@@ -1,55 +0,0 @@
1
- // src/actions/public/getMapEntry.ts
2
- async function getMapEntry(client, params) {
3
- const [address, name] = parseContractId(params.contract);
4
- const serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));
5
- const data = await client.request(`/v2/map_entry/${address}/${name}/${params.mapName}`, {
6
- method: "POST",
7
- body: serializedKey
8
- });
9
- if (typeof data?.data !== "string") {
10
- throw new MalformedResponseError(`getMapEntry: /v2/map_entry/${address}/${name}/${params.mapName} response is missing "data"`);
11
- }
12
- return deserializeCVBytes(data.data);
13
- }
14
-
15
- // src/actions/wallet/callContract.ts
16
- async function callContract(client, params) {
17
- const account = client.account;
18
- if (!account)
19
- throw new Error("Account required");
20
- const [contractAddress, contractName] = parseContractId(params.contract);
21
- if (isProviderAccount(account)) {
22
- assertNoFeeTierForProvider(params.fee);
23
- const result = await account.provider.request("stx_callContract", {
24
- contract: params.contract,
25
- functionName: params.functionName,
26
- functionArgs: params.functionArgs ?? []
27
- });
28
- return result.txid;
29
- }
30
- const nonce = params.nonce ?? await resolveNonce(client, account.address);
31
- const needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);
32
- const unsigned = buildContractCall({
33
- contractAddress,
34
- contractName,
35
- functionName: params.functionName,
36
- functionArgs: params.functionArgs ?? [],
37
- fee: needsFeeResolution ? 0n : params.fee,
38
- nonce,
39
- publicKey: account.publicKey,
40
- chain: client.chain,
41
- postConditionMode: params.postConditionMode,
42
- postConditions: params.postConditions
43
- });
44
- if (needsFeeResolution) {
45
- setUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));
46
- }
47
- const signed = await signTransactionWithAccount(unsigned, account);
48
- return broadcastWithNonceReset(client, {
49
- transaction: signed,
50
- address: account.address
51
- });
52
- }
53
-
54
- //# debugId=B9CB858E212A7D7264756E2164756E21
55
- //# sourceMappingURL=stacks-fjrpnkt3.cjs.map
@@ -1,11 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/actions/public/getMapEntry.ts", "../src/actions/wallet/callContract.ts"],
4
- "sourcesContent": [
5
- "import { deserializeCVBytes } from \"../../clarity/deserialize.ts\";\nimport { serializeCVBytes } from \"../../clarity/serialize.ts\";\nimport type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport { MalformedResponseError } from \"../../errors/response.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport { bytesToHex, with0x } from \"../../utils/encoding.ts\";\n\nexport type GetMapEntryParams = {\n\tcontract: string; // \"address.name\"\n\tmapName: string;\n\tkey: ClarityValue;\n};\n\nexport async function getMapEntry<T extends ClarityValue = ClarityValue>(\n\tclient: Client,\n\tparams: GetMapEntryParams,\n): Promise<T> {\n\tconst [address, name] = parseContractId(params.contract);\n\tconst serializedKey = with0x(bytesToHex(serializeCVBytes(params.key)));\n\n\tconst data = await client.request(\n\t\t`/v2/map_entry/${address}/${name}/${params.mapName}`,\n\t\t{\n\t\t\tmethod: \"POST\",\n\t\t\tbody: serializedKey,\n\t\t},\n\t);\n\n\tif (typeof data?.data !== \"string\") {\n\t\tthrow new MalformedResponseError(\n\t\t\t`getMapEntry: /v2/map_entry/${address}/${name}/${params.mapName} response is missing \"data\"`,\n\t\t);\n\t}\n\treturn deserializeCVBytes<T>(data.data);\n}\n",
6
- "import type { ClarityValue } from \"../../clarity/types.ts\";\nimport type { Client } from \"../../clients/types.ts\";\nimport type { PostCondition } from \"../../postconditions/types.ts\";\nimport { buildContractCall } from \"../../transactions/build.ts\";\nimport { signTransactionWithAccount } from \"../../transactions/signer.ts\";\nimport { parseContractId } from \"../../utils/address.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { broadcastWithNonceReset, resolveNonce } from \"./nonceManager.ts\";\nimport {\n\ttype FeeParam,\n\tassertNoFeeTierForProvider,\n\tisFeeTier,\n\tisProviderAccount,\n\tresolveFee,\n\tsetUnsignedFee,\n} from \"./utils.ts\";\n\nexport type CallContractParams = {\n\tcontract: string; // \"address.name\"\n\tfunctionName: string;\n\tfunctionArgs?: ClarityValue[];\n\tfee?: FeeParam;\n\tnonce?: IntegerType;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n};\n\n/** Build, sign, and broadcast a contract call */\nexport async function callContract(\n\tclient: Client,\n\tparams: CallContractParams,\n): Promise<string> {\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\n\t// Validate the contract id up front so both the provider and local paths\n\t// reject malformed input instead of forwarding it to the wallet.\n\tconst [contractAddress, contractName] = parseContractId(params.contract);\n\n\t// Provider: delegate to wallet\n\tif (isProviderAccount(account)) {\n\t\tassertNoFeeTierForProvider(params.fee);\n\t\tconst result = await account.provider.request(\"stx_callContract\", {\n\t\t\tcontract: params.contract,\n\t\t\tfunctionName: params.functionName,\n\t\t\tfunctionArgs: params.functionArgs ?? [],\n\t\t});\n\t\treturn result.txid;\n\t}\n\n\t// Local/Custom: build → sign → broadcast\n\tconst nonce = params.nonce ?? (await resolveNonce(client, account.address));\n\n\tconst needsFeeResolution = params.fee === undefined || isFeeTier(params.fee);\n\n\tconst unsigned = buildContractCall({\n\t\tcontractAddress,\n\t\tcontractName,\n\t\tfunctionName: params.functionName,\n\t\tfunctionArgs: params.functionArgs ?? [],\n\t\tfee: needsFeeResolution ? 0n : (params.fee as IntegerType),\n\t\tnonce,\n\t\tpublicKey: account.publicKey,\n\t\tchain: client.chain,\n\t\tpostConditionMode: params.postConditionMode,\n\t\tpostConditions: params.postConditions,\n\t});\n\n\tif (needsFeeResolution) {\n\t\tsetUnsignedFee(unsigned, await resolveFee(client, unsigned, params.fee));\n\t}\n\n\tconst signed = await signTransactionWithAccount(unsigned, account);\n\treturn broadcastWithNonceReset(client, {\n\t\ttransaction: signed,\n\t\taddress: account.address,\n\t});\n}\n"
7
- ],
8
- "mappings": ";AAcA,eAAsB,WAAkD,CACvE,QACA,QACa;AAAA,EACb,OAAO,SAAS,QAAQ,gBAAgB,OAAO,QAAQ;AAAA,EACvD,MAAM,gBAAgB,OAAO,WAAW,iBAAiB,OAAO,GAAG,CAAC,CAAC;AAAA,EAErE,MAAM,OAAO,MAAM,OAAO,QACzB,iBAAiB,WAAW,QAAQ,OAAO,WAC3C;AAAA,IACC,QAAQ;AAAA,IACR,MAAM;AAAA,EACP,CACD;AAAA,EAEA,IAAI,OAAO,MAAM,SAAS,UAAU;AAAA,IACnC,MAAM,IAAI,uBACT,8BAA8B,WAAW,QAAQ,OAAO,oCACzD;AAAA,EACD;AAAA,EACA,OAAO,mBAAsB,KAAK,IAAI;AAAA;;;ACNvC,eAAsB,YAAY,CACjC,QACA,QACkB;AAAA,EAClB,MAAM,UAAU,OAAO;AAAA,EACvB,IAAI,CAAC;AAAA,IAAS,MAAM,IAAI,MAAM,kBAAkB;AAAA,EAIhD,OAAO,iBAAiB,gBAAgB,gBAAgB,OAAO,QAAQ;AAAA,EAGvE,IAAI,kBAAkB,OAAO,GAAG;AAAA,IAC/B,2BAA2B,OAAO,GAAG;AAAA,IACrC,MAAM,SAAS,MAAM,QAAQ,SAAS,QAAQ,oBAAoB;AAAA,MACjE,UAAU,OAAO;AAAA,MACjB,cAAc,OAAO;AAAA,MACrB,cAAc,OAAO,gBAAgB,CAAC;AAAA,IACvC,CAAC;AAAA,IACD,OAAO,OAAO;AAAA,EACf;AAAA,EAGA,MAAM,QAAQ,OAAO,SAAU,MAAM,aAAa,QAAQ,QAAQ,OAAO;AAAA,EAEzE,MAAM,qBAAqB,OAAO,QAAQ,aAAa,UAAU,OAAO,GAAG;AAAA,EAE3E,MAAM,WAAW,kBAAkB;AAAA,IAClC;AAAA,IACA;AAAA,IACA,cAAc,OAAO;AAAA,IACrB,cAAc,OAAO,gBAAgB,CAAC;AAAA,IACtC,KAAK,qBAAqB,KAAM,OAAO;AAAA,IACvC;AAAA,IACA,WAAW,QAAQ;AAAA,IACnB,OAAO,OAAO;AAAA,IACd,mBAAmB,OAAO;AAAA,IAC1B,gBAAgB,OAAO;AAAA,EACxB,CAAC;AAAA,EAED,IAAI,oBAAoB;AAAA,IACvB,eAAe,UAAU,MAAM,WAAW,QAAQ,UAAU,OAAO,GAAG,CAAC;AAAA,EACxE;AAAA,EAEA,MAAM,SAAS,MAAM,2BAA2B,UAAU,OAAO;AAAA,EACjE,OAAO,wBAAwB,QAAQ;AAAA,IACtC,aAAa;AAAA,IACb,SAAS,QAAQ;AAAA,EAClB,CAAC;AAAA;",
9
- "debugId": "B9CB858E212A7D7264756E2164756E21",
10
- "names": []
11
- }
@@ -1,44 +0,0 @@
1
- import {
2
- isProviderAccount,
3
- resolveFee,
4
- resolveNonce
5
- } from "./stacks-9d2d0qjc.js";
6
- import {
7
- AuthType,
8
- createSingleSigSpendingCondition,
9
- signSponsorWithAccount
10
- } from "./stacks-jx146qf1.js";
11
- import {
12
- intToBigInt
13
- } from "./stacks-qs5fzts5.js";
14
-
15
- // src/actions/wallet/sponsorTransaction.ts
16
- async function sponsorTransaction(client, params) {
17
- const { transaction } = params;
18
- if (transaction.auth.authType !== AuthType.Sponsored) {
19
- throw new Error("Transaction must have sponsored authorization");
20
- }
21
- const account = client.account;
22
- if (!account)
23
- throw new Error("Account required");
24
- if (isProviderAccount(account)) {
25
- throw new Error("Provider accounts cannot sponsor transactions");
26
- }
27
- const nonce = params.nonce != null ? intToBigInt(params.nonce) : await resolveNonce(client, account.address);
28
- const fee = await resolveFee(client, transaction, params.fee);
29
- const sponsorCondition = createSingleSigSpendingCondition(account.publicKey, nonce, fee);
30
- const auth = transaction.auth;
31
- const sponsored = {
32
- ...transaction,
33
- auth: {
34
- ...auth,
35
- sponsorSpendingCondition: sponsorCondition
36
- }
37
- };
38
- return signSponsorWithAccount(sponsored, account);
39
- }
40
-
41
- export { sponsorTransaction };
42
-
43
- //# debugId=AD4711CB97F1F3EB64756E2164756E21
44
- //# sourceMappingURL=stacks-w8tt1fmt.js.map
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/actions/wallet/sponsorTransaction.ts"],
4
- "sourcesContent": [
5
- "import type { Client } from \"../../clients/types.ts\";\nimport { createSingleSigSpendingCondition } from \"../../transactions/authorization.ts\";\nimport { signSponsorWithAccount } from \"../../transactions/signer.ts\";\nimport {\n\tAuthType,\n\ttype SponsoredAuthorization,\n\ttype StacksTransaction,\n} from \"../../transactions/types.ts\";\nimport type { IntegerType } from \"../../utils/encoding.ts\";\nimport { intToBigInt } from \"../../utils/encoding.ts\";\nimport { resolveNonce } from \"./nonceManager.ts\";\nimport { type FeeParam, isProviderAccount, resolveFee } from \"./utils.ts\";\n\nexport type SponsorTransactionParams = {\n\ttransaction: StacksTransaction;\n\tfee?: FeeParam;\n\tnonce?: IntegerType;\n};\n\n/** Sponsor a transaction: set sponsor spending condition, sign as sponsor */\nexport async function sponsorTransaction(\n\tclient: Client,\n\tparams: SponsorTransactionParams,\n): Promise<StacksTransaction> {\n\tconst { transaction } = params;\n\n\tif (transaction.auth.authType !== AuthType.Sponsored) {\n\t\tthrow new Error(\"Transaction must have sponsored authorization\");\n\t}\n\n\tconst account = client.account;\n\tif (!account) throw new Error(\"Account required\");\n\tif (isProviderAccount(account)) {\n\t\tthrow new Error(\"Provider accounts cannot sponsor transactions\");\n\t}\n\n\t// Resolve sponsor nonce\n\tconst nonce =\n\t\tparams.nonce != null\n\t\t\t? intToBigInt(params.nonce)\n\t\t\t: await resolveNonce(client, account.address);\n\n\t// Resolve sponsor fee. Estimation failure falls back to the minimum relay\n\t// fee instead of 0 (a 0-fee tx would be rejected at broadcast).\n\tconst fee = await resolveFee(client, transaction, params.fee);\n\n\t// Create sponsor spending condition\n\tconst sponsorCondition = createSingleSigSpendingCondition(\n\t\taccount.publicKey,\n\t\tnonce,\n\t\tfee,\n\t);\n\n\t// Set sponsor spending condition on the tx\n\tconst auth = transaction.auth as SponsoredAuthorization;\n\tconst sponsored: StacksTransaction = {\n\t\t...transaction,\n\t\tauth: {\n\t\t\t...auth,\n\t\t\tsponsorSpendingCondition: sponsorCondition,\n\t\t},\n\t};\n\n\t// Sign as sponsor\n\treturn signSponsorWithAccount(sponsored, account);\n}\n"
6
- ],
7
- "mappings": ";;;;;;;;;;;;;;;AAoBA,eAAsB,kBAAkB,CACvC,QACA,QAC6B;AAAA,EAC7B,QAAQ,gBAAgB;AAAA,EAExB,IAAI,YAAY,KAAK,aAAa,SAAS,WAAW;AAAA,IACrD,MAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AAAA,EAEA,MAAM,UAAU,OAAO;AAAA,EACvB,IAAI,CAAC;AAAA,IAAS,MAAM,IAAI,MAAM,kBAAkB;AAAA,EAChD,IAAI,kBAAkB,OAAO,GAAG;AAAA,IAC/B,MAAM,IAAI,MAAM,+CAA+C;AAAA,EAChE;AAAA,EAGA,MAAM,QACL,OAAO,SAAS,OACb,YAAY,OAAO,KAAK,IACxB,MAAM,aAAa,QAAQ,QAAQ,OAAO;AAAA,EAI9C,MAAM,MAAM,MAAM,WAAW,QAAQ,aAAa,OAAO,GAAG;AAAA,EAG5D,MAAM,mBAAmB,iCACxB,QAAQ,WACR,OACA,GACD;AAAA,EAGA,MAAM,OAAO,YAAY;AAAA,EACzB,MAAM,YAA+B;AAAA,OACjC;AAAA,IACH,MAAM;AAAA,SACF;AAAA,MACH,0BAA0B;AAAA,IAC3B;AAAA,EACD;AAAA,EAGA,OAAO,uBAAuB,WAAW,OAAO;AAAA;",
8
- "debugId": "AD4711CB97F1F3EB64756E2164756E21",
9
- "names": []
10
- }
@@ -1,3 +0,0 @@
1
-
2
- //# debugId=AAC6E250E380EF1864756E2164756E21
3
- //# sourceMappingURL=stacks-z53fwfcm.js.map
@@ -1,9 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [
5
- ],
6
- "mappings": "",
7
- "debugId": "AAC6E250E380EF1864756E2164756E21",
8
- "names": []
9
- }
@@ -1,65 +0,0 @@
1
- // src/x402/index.ts
2
- var exports_x402 = {};
3
- __export(exports_x402, {
4
- sponsorAndBroadcast: () => sponsorAndBroadcast,
5
- buildExactTransfer: () => buildExactTransfer
6
- });
7
- module.exports = __toCommonJS(exports_x402);
8
-
9
- // src/x402/build.ts
10
- function buildExactTransfer(options) {
11
- const { asset, amount, payTo, payer, payerPublicKey, accountNonce, chain } = options;
12
- if (utf8ToBytes(options.nonce).byteLength > MEMO_MAX_LENGTH_BYTES) {
13
- throw new Error(`x402 nonce exceeds the ${MEMO_MAX_LENGTH_BYTES}-byte memo budget`);
14
- }
15
- if (asset.kind === "stx") {
16
- return buildTokenTransfer({
17
- recipient: payTo,
18
- amount,
19
- memo: options.nonce,
20
- fee: 0,
21
- nonce: accountNonce,
22
- publicKey: payerPublicKey,
23
- chain,
24
- sponsored: true
25
- });
26
- }
27
- const [contractAddress, contractName] = parseContractId(asset.contractId);
28
- const postConditions = [
29
- Pc.principal(payer).willSendEq(amount).ft(asset.contractId, asset.assetName)
30
- ];
31
- return buildContractCall({
32
- contractAddress,
33
- contractName,
34
- functionName: "transfer",
35
- functionArgs: [
36
- Cl.uint(amount),
37
- Cl.principal(payer),
38
- Cl.principal(payTo),
39
- Cl.some(Cl.bufferFromUtf8(options.nonce))
40
- ],
41
- fee: 0,
42
- nonce: accountNonce,
43
- publicKey: payerPublicKey,
44
- chain,
45
- postConditionMode: "deny",
46
- postConditions,
47
- sponsored: true
48
- });
49
- }
50
- // src/x402/settle.ts
51
- async function sponsorAndBroadcast(client, signedTxHex, options = {}) {
52
- const transaction = deserializeTransaction(signedTxHex);
53
- const sponsored = await sponsorTransaction(client, {
54
- transaction,
55
- fee: options.fee,
56
- nonce: options.nonce
57
- });
58
- return sendTransaction(client, {
59
- transaction: sponsored,
60
- wait: options.wait
61
- });
62
- }
63
-
64
- //# debugId=26F0FC52B71944B464756E2164756E21
65
- //# sourceMappingURL=index.cjs.map
@@ -1,11 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/x402/build.ts", "../src/x402/settle.ts"],
4
- "sourcesContent": [
5
- "import type { StacksChain } from \"../chains/types.ts\";\nimport { Cl } from \"../clarity/values.ts\";\nimport { Pc } from \"../postconditions/builder.ts\";\nimport type { PostCondition } from \"../postconditions/types.ts\";\nimport {\n\tbuildContractCall,\n\tbuildTokenTransfer,\n} from \"../transactions/build.ts\";\nimport {\n\tMEMO_MAX_LENGTH_BYTES,\n\ttype StacksTransaction,\n} from \"../transactions/types.ts\";\nimport { parseContractId } from \"../utils/address.ts\";\nimport { type IntegerType, utf8ToBytes } from \"../utils/encoding.ts\";\n\n/**\n * The asset an x402 payment moves. Either native STX or a SIP-010 token,\n * in which case the fully-qualified contract id and the fungible-token asset\n * name (the `::<asset-name>` suffix, e.g. `sbtc-token`) are both required —\n * the asset name is not always equal to the contract name.\n */\nexport type X402Asset =\n\t| { kind: \"stx\" }\n\t| { kind: \"sip010\"; contractId: string; assetName: string };\n\nexport type BuildExactTransferOptions = {\n\t/** The asset and amount to move. */\n\tasset: X402Asset;\n\tamount: IntegerType;\n\t/** Recipient principal (the resource server's `payTo`). */\n\tpayTo: string;\n\t/** Origin/payer principal — pinned by the post-condition. */\n\tpayer: string;\n\t/** Origin compressed public key (the payer signs origin-only). */\n\tpayerPublicKey: string;\n\t/** The payer account's next nonce. */\n\taccountNonce: IntegerType;\n\t/**\n\t * The x402 challenge nonce, carried in the on-chain memo so the facilitator\n\t * can correlate the settled tx with the challenge. Bound to ≤ 34 bytes\n\t * (UTF-8) — both the STX memo and the SIP-010 `(buff 34)` memo arg cap there.\n\t */\n\tnonce: string;\n\tchain?: StacksChain;\n};\n\n/**\n * Build an exact-amount, Deny-mode, post-conditioned, **sponsored** transfer\n * (origin-only, un-broadcast). The origin sets fee `0`; the facilitator's\n * sponsor fills in + pays the fee at settle time. The Deny-mode post-condition\n * asserts EXACTLY `amount` leaves `payer` to `payTo`, so settlement aborts\n * on-chain if anything differs — the \"exact amount\" x402 guarantee is enforced\n * by Clarity, not just by facilitator simulation.\n */\nexport function buildExactTransfer(\n\toptions: BuildExactTransferOptions,\n): StacksTransaction {\n\tconst { asset, amount, payTo, payer, payerPublicKey, accountNonce, chain } =\n\t\toptions;\n\n\tif (utf8ToBytes(options.nonce).byteLength > MEMO_MAX_LENGTH_BYTES) {\n\t\tthrow new Error(\n\t\t\t`x402 nonce exceeds the ${MEMO_MAX_LENGTH_BYTES}-byte memo budget`,\n\t\t);\n\t}\n\n\tif (asset.kind === \"stx\") {\n\t\t// A TokenTransfer payload CANNOT carry post-conditions (Stacks consensus\n\t\t// rejects it: \"TokenTransfer transactions do not support post-conditions\").\n\t\t// STX exactness is inherent — the amount + recipient are in the signed\n\t\t// payload, so there is nothing a post-condition would add.\n\t\treturn buildTokenTransfer({\n\t\t\trecipient: payTo,\n\t\t\tamount,\n\t\t\tmemo: options.nonce,\n\t\t\tfee: 0,\n\t\t\tnonce: accountNonce,\n\t\t\tpublicKey: payerPublicKey,\n\t\t\tchain,\n\t\t\tsponsored: true,\n\t\t});\n\t}\n\n\tconst [contractAddress, contractName] = parseContractId(asset.contractId);\n\tconst postConditions: PostCondition[] = [\n\t\tPc.principal(payer)\n\t\t\t.willSendEq(amount)\n\t\t\t.ft(asset.contractId, asset.assetName),\n\t];\n\t// SIP-010: (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34))))\n\treturn buildContractCall({\n\t\tcontractAddress,\n\t\tcontractName,\n\t\tfunctionName: \"transfer\",\n\t\tfunctionArgs: [\n\t\t\tCl.uint(amount),\n\t\t\tCl.principal(payer),\n\t\t\tCl.principal(payTo),\n\t\t\tCl.some(Cl.bufferFromUtf8(options.nonce)),\n\t\t],\n\t\tfee: 0,\n\t\tnonce: accountNonce,\n\t\tpublicKey: payerPublicKey,\n\t\tchain,\n\t\tpostConditionMode: \"deny\",\n\t\tpostConditions,\n\t\tsponsored: true,\n\t});\n}\n",
6
- "import type { TransactionReceipt } from \"../actions/public/txSources.ts\";\nimport { sendTransaction } from \"../actions/wallet/sendTransaction.ts\";\nimport { sponsorTransaction } from \"../actions/wallet/sponsorTransaction.ts\";\nimport type { Client } from \"../clients/types.ts\";\nimport { deserializeTransaction } from \"../transactions/wire/deserialize.ts\";\nimport type { IntegerType } from \"../utils/encoding.ts\";\n\nexport type SponsorAndBroadcastOptions = {\n\t/** Override the sponsor fee (µSTX). Defaults to a fee estimate. */\n\tfee?: IntegerType;\n\t/** Override the sponsor account nonce. Defaults to the on-chain nonce. */\n\tnonce?: IntegerType;\n\t/**\n\t * Wait for the payment to be mined before returning (`true` = 1\n\t * confirmation, a number = that many). Settlement rejects if the payment\n\t * aborts or drops, instead of reporting a txid that never lands.\n\t */\n\twait?: boolean | number;\n};\n\nexport type SponsorAndBroadcastResult = {\n\ttxid: string;\n\t/** Present when `wait` was requested. */\n\treceipt?: TransactionReceipt;\n};\n\n/**\n * Take an origin-signed, sponsored transfer (hex) from the payer, sponsor-sign\n * it with `client`'s account (paying the STX fee), and broadcast it.\n *\n * The payer never holds STX: they sign origin-only with fee `0`; this fills in\n * the sponsor spending condition + fee and POSTs to `/v2/transactions`. The\n * sponsor cannot grief the payer — amount/recipient/asset are pinned by the\n * origin signature + Deny-mode post-conditions baked into the tx.\n *\n * @param client a wallet client whose `account` is the funded sponsor signer.\n * @param signedTxHex the payer's origin-signed sponsored tx, hex-serialized.\n */\nexport async function sponsorAndBroadcast(\n\tclient: Client,\n\tsignedTxHex: string,\n\toptions: SponsorAndBroadcastOptions = {},\n): Promise<SponsorAndBroadcastResult> {\n\tconst transaction = deserializeTransaction(signedTxHex);\n\tconst sponsored = await sponsorTransaction(client, {\n\t\ttransaction,\n\t\tfee: options.fee,\n\t\tnonce: options.nonce,\n\t});\n\treturn sendTransaction(client, {\n\t\ttransaction: sponsored,\n\t\twait: options.wait,\n\t});\n}\n"
7
- ],
8
- "mappings": ";;;;;;;;;AAsDO,SAAS,kBAAkB,CACjC,SACoB;AAAA,EACpB,QAAQ,OAAO,QAAQ,OAAO,OAAO,gBAAgB,cAAc,UAClE;AAAA,EAED,IAAI,YAAY,QAAQ,KAAK,EAAE,aAAa,uBAAuB;AAAA,IAClE,MAAM,IAAI,MACT,0BAA0B,wCAC3B;AAAA,EACD;AAAA,EAEA,IAAI,MAAM,SAAS,OAAO;AAAA,IAKzB,OAAO,mBAAmB;AAAA,MACzB,WAAW;AAAA,MACX;AAAA,MACA,MAAM,QAAQ;AAAA,MACd,KAAK;AAAA,MACL,OAAO;AAAA,MACP,WAAW;AAAA,MACX;AAAA,MACA,WAAW;AAAA,IACZ,CAAC;AAAA,EACF;AAAA,EAEA,OAAO,iBAAiB,gBAAgB,gBAAgB,MAAM,UAAU;AAAA,EACxE,MAAM,iBAAkC;AAAA,IACvC,GAAG,UAAU,KAAK,EAChB,WAAW,MAAM,EACjB,GAAG,MAAM,YAAY,MAAM,SAAS;AAAA,EACvC;AAAA,EAEA,OAAO,kBAAkB;AAAA,IACxB;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,cAAc;AAAA,MACb,GAAG,KAAK,MAAM;AAAA,MACd,GAAG,UAAU,KAAK;AAAA,MAClB,GAAG,UAAU,KAAK;AAAA,MAClB,GAAG,KAAK,GAAG,eAAe,QAAQ,KAAK,CAAC;AAAA,IACzC;AAAA,IACA,KAAK;AAAA,IACL,OAAO;AAAA,IACP,WAAW;AAAA,IACX;AAAA,IACA,mBAAmB;AAAA,IACnB;AAAA,IACA,WAAW;AAAA,EACZ,CAAC;AAAA;;ACrEF,eAAsB,mBAAmB,CACxC,QACA,aACA,UAAsC,CAAC,GACF;AAAA,EACrC,MAAM,cAAc,uBAAuB,WAAW;AAAA,EACtD,MAAM,YAAY,MAAM,mBAAmB,QAAQ;AAAA,IAClD;AAAA,IACA,KAAK,QAAQ;AAAA,IACb,OAAO,QAAQ;AAAA,EAChB,CAAC;AAAA,EACD,OAAO,gBAAgB,QAAQ;AAAA,IAC9B,aAAa;AAAA,IACb,MAAM,QAAQ;AAAA,EACf,CAAC;AAAA;",
9
- "debugId": "26F0FC52B71944B464756E2164756E21",
10
- "names": []
11
- }