@sun-protocol/sun-sdk-runtime 0.1.0-beta.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.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @sun-protocol/sun-sdk-runtime
2
+
3
+ TRON chain clients, wallet adapters, contract access, signing, and transaction broadcasting for SUN SDK.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @sun-protocol/sun-sdk-runtime tronweb
9
+ ```
10
+
11
+ ## Example
12
+
13
+ ```ts
14
+ import {
15
+ createPrivateKeyWalletAdapter,
16
+ createTronWebClient,
17
+ } from '@sun-protocol/sun-sdk-runtime/node'
18
+
19
+ const tronClient = createTronWebClient({ network: 'mainnet', tronWeb })
20
+ const wallet = createPrivateKeyWalletAdapter({ privateKey, tronWeb })
21
+ ```
22
+
23
+ The root entry exports runtime types, `createRuntime`, balance reads, aggregate multicall, and transaction result helpers. Environment-specific entry points are `/browser`, `/tronweb`, `/node`, and `/mock`.
24
+
25
+ This is the only SUN SDK package that directly handles wallets, signing, broadcasting, and TronWeb. `tronweb` is an optional peer dependency and is needed only by TronWeb-based adapters.
26
+
27
+ Requires Node.js 20 or a modern browser, depending on the selected entry point.
28
+
29
+ [Full API documentation](https://github.com/sun-protocol/sun-sdk/blob/main/docs/sdk/api/runtime.md)
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/browser.ts
21
+ var browser_exports = {};
22
+ __export(browser_exports, {
23
+ createBrowserWalletAdapter: () => createBrowserWalletAdapter,
24
+ normalizeTxResult: () => normalizeTxResult,
25
+ walletSupportsTypedData: () => walletSupportsTypedData
26
+ });
27
+ module.exports = __toCommonJS(browser_exports);
28
+
29
+ // src/wallets/browser.ts
30
+ var import_sun_sdk_core = require("@sun-protocol/sun-sdk-core");
31
+ function createBrowserWalletAdapter(input) {
32
+ return {
33
+ kind: "tronWalletAdapter",
34
+ capabilities: {
35
+ signTransaction: input.signTransaction !== void 0,
36
+ signAndSendTransaction: input.signAndSendTransaction !== void 0,
37
+ signTypedData: input.signTypedData !== void 0,
38
+ userInteractive: true
39
+ },
40
+ ...input.sendStrategy !== void 0 ? { sendStrategy: input.sendStrategy } : {},
41
+ async getAddress() {
42
+ return (0, import_sun_sdk_core.assertTronAddress)(input.address, "wallet address");
43
+ },
44
+ ...input.signTransaction !== void 0 ? { signTransaction: input.signTransaction } : {},
45
+ ...input.signAndSendTransaction !== void 0 ? { signAndSendTransaction: input.signAndSendTransaction } : {},
46
+ ...input.signTypedData !== void 0 ? { signTypedData: input.signTypedData } : {}
47
+ };
48
+ }
49
+
50
+ // src/tx/normalize-result.ts
51
+ var import_sun_sdk_core2 = require("@sun-protocol/sun-sdk-core");
52
+ function readTxid(value) {
53
+ if (typeof value === "string" && value.length > 0) {
54
+ return value;
55
+ }
56
+ if (!value || typeof value !== "object") {
57
+ return null;
58
+ }
59
+ const record = value;
60
+ const direct = record.txid ?? record.txID ?? record.transactionId ?? record.txHash;
61
+ if (typeof direct === "string" && direct.length > 0) {
62
+ return direct;
63
+ }
64
+ const transaction = record.transaction;
65
+ if (transaction && typeof transaction === "object") {
66
+ return readTxid(transaction);
67
+ }
68
+ return null;
69
+ }
70
+ function hasBroadcastFailure(value) {
71
+ if (!value || typeof value !== "object") {
72
+ return false;
73
+ }
74
+ const record = value;
75
+ return record.result === false || typeof record.code === "string" || typeof record.Error === "string";
76
+ }
77
+ function normalizeTxResult(raw) {
78
+ if (hasBroadcastFailure(raw)) {
79
+ throw new import_sun_sdk_core2.SDKError("SDK_RUNTIME_ERROR", "Transaction broadcast failed", { raw });
80
+ }
81
+ const txid = readTxid(raw);
82
+ if (!txid) {
83
+ throw new import_sun_sdk_core2.SDKError("SDK_RUNTIME_ERROR", "Unable to find txid in transaction result", { raw });
84
+ }
85
+ return { txid, raw };
86
+ }
87
+
88
+ // src/wallets/capabilities.ts
89
+ function walletSupportsTypedData(capabilities) {
90
+ return capabilities.signTypedData === true;
91
+ }
92
+ // Annotate the CommonJS export names for ESM import in node:
93
+ 0 && (module.exports = {
94
+ createBrowserWalletAdapter,
95
+ normalizeTxResult,
96
+ walletSupportsTypedData
97
+ });
98
+ //# sourceMappingURL=browser.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/browser.ts","../src/wallets/browser.ts","../src/tx/normalize-result.ts","../src/wallets/capabilities.ts"],"sourcesContent":["export type {\n SignedTronTransaction,\n TxResult,\n TypedDataPayload,\n UnsignedTronTransaction,\n WalletAdapter,\n WalletCapabilities,\n WalletSendStrategy,\n} from './types.js'\nexport { createBrowserWalletAdapter, type BrowserWalletInput } from './wallets/browser.js'\nexport { normalizeTxResult } from './tx/normalize-result.js'\nexport { walletSupportsTypedData } from './wallets/capabilities.js'\n","import { assertTronAddress, type TronAddress } from '@sun-protocol/sun-sdk-core'\nimport type {\n SignedTronTransaction,\n TxResult,\n TypedDataPayload,\n UnsignedTronTransaction,\n WalletAdapter,\n WalletSendStrategy,\n} from '../types.js'\n\nexport interface BrowserWalletInput {\n readonly address: TronAddress | string\n readonly sendStrategy?: WalletSendStrategy\n signTransaction?(tx: UnsignedTronTransaction): Promise<SignedTronTransaction>\n signAndSendTransaction?(tx: UnsignedTronTransaction): Promise<TxResult | unknown>\n signTypedData?(payload: TypedDataPayload): Promise<string>\n}\n\nexport function createBrowserWalletAdapter(input: BrowserWalletInput): WalletAdapter {\n return {\n kind: 'tronWalletAdapter',\n capabilities: {\n signTransaction: input.signTransaction !== undefined,\n signAndSendTransaction: input.signAndSendTransaction !== undefined,\n signTypedData: input.signTypedData !== undefined,\n userInteractive: true,\n },\n ...(input.sendStrategy !== undefined ? { sendStrategy: input.sendStrategy } : {}),\n async getAddress() {\n return assertTronAddress(input.address, 'wallet address')\n },\n ...(input.signTransaction !== undefined ? { signTransaction: input.signTransaction } : {}),\n ...(input.signAndSendTransaction !== undefined ? { signAndSendTransaction: input.signAndSendTransaction } : {}),\n ...(input.signTypedData !== undefined ? { signTypedData: input.signTypedData } : {}),\n }\n}\n","import { SDKError } from '@sun-protocol/sun-sdk-core'\nimport type { TxResult } from '../types.js'\n\nfunction readTxid(value: unknown): string | null {\n if (typeof value === 'string' && value.length > 0) {\n return value\n }\n\n if (!value || typeof value !== 'object') {\n return null\n }\n\n const record = value as Record<string, unknown>\n const direct = record.txid ?? record.txID ?? record.transactionId ?? record.txHash\n if (typeof direct === 'string' && direct.length > 0) {\n return direct\n }\n\n const transaction = record.transaction\n if (transaction && typeof transaction === 'object') {\n return readTxid(transaction)\n }\n\n return null\n}\n\nfunction hasBroadcastFailure(value: unknown): boolean {\n if (!value || typeof value !== 'object') {\n return false\n }\n\n const record = value as Record<string, unknown>\n return record.result === false || typeof record.code === 'string' || typeof record.Error === 'string'\n}\n\nexport function normalizeTxResult(raw: unknown): TxResult {\n if (hasBroadcastFailure(raw)) {\n throw new SDKError('SDK_RUNTIME_ERROR', 'Transaction broadcast failed', { raw })\n }\n\n const txid = readTxid(raw)\n if (!txid) {\n throw new SDKError('SDK_RUNTIME_ERROR', 'Unable to find txid in transaction result', { raw })\n }\n return { txid, raw }\n}\n","import type { WalletCapabilities } from '../types.js'\n\nexport function walletSupportsTypedData(capabilities: Pick<WalletCapab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,OAAyB;AACpD,MAAI,CAAC,SAAS,OAAO,UAAU,UAAU;AACvC,WAAO;AAAA,EACT;AAEA,QAAM,SAAS;AACf,SAAO,OAAO,WAAW,SAAS,OAAO,OAAO,SAAS,YAAY,OAAO,OAAO,UAAU;AAC/F;AAEO,SAAS,kBAAkB,KAAwB;AACxD,MAAI,oBAAoB,GAAG,GAAG;AAC5B,UAAM,IAAI,8BAAS,qBAAqB,gCAAgC,EAAE,IAAI,CAAC;AAAA,EACjF;AAEA,QAAM,OAAO,SAAS,GAAG;AACzB,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,8BAAS,qBAAqB,6CAA6C,EAAE,IAAI,CAAC;AAAA,EAC9F;AACA,SAAO,EAAE,MAAM,IAAI;AACrB;;;AC3CO,SAAS,wBAAwB,cAAkE;AACxG,SAAO,aAAa,kBAAkB;AACxC;","names":["import_sun_sdk_core"]}
@@ -0,0 +1,16 @@
1
+ import { W as WalletSendStrategy, U as UnsignedTronTransaction, S as SignedTronTransaction, T as TxResult, a as TypedDataPayload, b as WalletAdapter } from './types-CZnHFnQK.cjs';
2
+ export { c as WalletCapabilities } from './types-CZnHFnQK.cjs';
3
+ import { TronAddress } from '@sun-protocol/sun-sdk-core';
4
+ export { n as normalizeTxResult, w as walletSupportsTypedData } from './capabilities-CpGxiDmg.cjs';
5
+ import '@sun-protocol/sun-sdk-chains';
6
+
7
+ interface BrowserWalletInput {
8
+ readonly address: TronAddress | string;
9
+ readonly sendStrategy?: WalletSendStrategy;
10
+ signTransaction?(tx: UnsignedTronTransaction): Promise<SignedTronTransaction>;
11
+ signAndSendTransaction?(tx: UnsignedTronTransaction): Promise<TxResult | unknown>;
12
+ signTypedData?(payload: TypedDataPayload): Promise<string>;
13
+ }
14
+ declare function createBrowserWalletAdapter(input: BrowserWalletInput): WalletAdapter;
15
+
16
+ export { type BrowserWalletInput, SignedTronTransaction, TxResult, TypedDataPayload, UnsignedTronTransaction, WalletAdapter, WalletSendStrategy, createBrowserWalletAdapter };
@@ -0,0 +1,16 @@
1
+ import { W as WalletSendStrategy, U as UnsignedTronTransaction, S as SignedTronTransaction, T as TxResult, a as TypedDataPayload, b as WalletAdapter } from './types-CZnHFnQK.js';
2
+ export { c as WalletCapabilities } from './types-CZnHFnQK.js';
3
+ import { TronAddress } from '@sun-protocol/sun-sdk-core';
4
+ export { n as normalizeTxResult, w as walletSupportsTypedData } from './capabilities-0q9k2fGU.js';
5
+ import '@sun-protocol/sun-sdk-chains';
6
+
7
+ interface BrowserWalletInput {
8
+ readonly address: TronAddress | string;
9
+ readonly sendStrategy?: WalletSendStrategy;
10
+ signTransaction?(tx: UnsignedTronTransaction): Promise<SignedTronTransaction>;
11
+ signAndSendTransaction?(tx: UnsignedTronTransaction): Promise<TxResult | unknown>;
12
+ signTypedData?(payload: TypedDataPayload): Promise<string>;
13
+ }
14
+ declare function createBrowserWalletAdapter(input: BrowserWalletInput): WalletAdapter;
15
+
16
+ export { type BrowserWalletInput, SignedTronTransaction, TxResult, TypedDataPayload, UnsignedTronTransaction, WalletAdapter, WalletSendStrategy, createBrowserWalletAdapter };
@@ -0,0 +1,33 @@
1
+ import {
2
+ walletSupportsTypedData
3
+ } from "./chunk-NVRQ3Z7L.js";
4
+ import {
5
+ normalizeTxResult
6
+ } from "./chunk-VYEUIAUC.js";
7
+
8
+ // src/wallets/browser.ts
9
+ import { assertTronAddress } from "@sun-protocol/sun-sdk-core";
10
+ function createBrowserWalletAdapter(input) {
11
+ return {
12
+ kind: "tronWalletAdapter",
13
+ capabilities: {
14
+ signTransaction: input.signTransaction !== void 0,
15
+ signAndSendTransaction: input.signAndSendTransaction !== void 0,
16
+ signTypedData: input.signTypedData !== void 0,
17
+ userInteractive: true
18
+ },
19
+ ...input.sendStrategy !== void 0 ? { sendStrategy: input.sendStrategy } : {},
20
+ async getAddress() {
21
+ return assertTronAddress(input.address, "wallet address");
22
+ },
23
+ ...input.signTransaction !== void 0 ? { signTransaction: input.signTransaction } : {},
24
+ ...input.signAndSendTransaction !== void 0 ? { signAndSendTransaction: input.signAndSendTransaction } : {},
25
+ ...input.signTypedData !== void 0 ? { signTypedData: input.signTypedData } : {}
26
+ };
27
+ }
28
+ export {
29
+ createBrowserWalletAdapter,
30
+ normalizeTxResult,
31
+ walletSupportsTypedData
32
+ };
33
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/wallets/browser.ts"],"sourcesContent":["import { assertTronAddress, type TronAddress } from '@sun-protocol/sun-sdk-core'\nimport type {\n SignedTronTransaction,\n TxResult,\n TypedDataPayload,\n UnsignedTronTransaction,\n WalletAdapter,\n WalletSendStrategy,\n} from '../types.js'\n\nexport interface BrowserWalletInput {\n readonly address: TronAddress | string\n readonly sendStrategy?: WalletSendStrategy\n signTransaction?(tx: UnsignedTronTransaction): Promise<SignedTronTransaction>\n signAndSendTransaction?(tx: UnsignedTronTransaction): Promise<TxResult | unknown>\n signTypedData?(payload: TypedDataPayload): Promise<string>\n}\n\nexport function createBrowserWalletAdapter(input: BrowserWalletInput): WalletAdapter {\n return {\n kind: 'tronWalletAdapter',\n capabilities: {\n signTransaction: input.signTransaction !== undefined,\n signAndSendTransaction: input.signAndSendTransaction !== undefined,\n signTypedData: input.signTypedData !== undefined,\n userInteractive: true,\n },\n ...(input.sendStrategy !== undefined ? { sendStrategy: input.sendStrategy } : {}),\n async getAddress() {\n return assertTronAddress(input.address, 'wallet address')\n },\n ...(input.signTransaction !== undefined ? { signTransaction: input.signTransaction } : {}),\n ...(input.signAndSendTransaction !== undefined ? { signAndSendTransaction: input.signAndSendTransaction } : {}),\n ...(input.signTypedData !== undefined ? { signTypedData: input.signTypedData } : {}),\n }\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,yBAA2C;AAkB7C,SAAS,2BAA2B,OAA0C;AACnF,SAAO;AAAA,IACL,MAAM;AAAA,IACN,cAAc;AAAA,MACZ,iBAAiB,MAAM,oBAAoB;AAAA,MAC3C,wBAAwB,MAAM,2BAA2B;AAAA,MACzD,eAAe,MAAM,kBAAkB;AAAA,MACvC,iBAAiB;AAAA,IACnB;AAAA,IACA,GAAI,MAAM,iBAAiB,SAAY,EAAE,cAAc,MAAM,aAAa,IAAI,CAAC;AAAA,IAC/E,MAAM,aAAa;AACjB,aAAO,kBAAkB,MAAM,SAAS,gBAAgB;AAAA,IAC1D;AAAA,IACA,GAAI,MAAM,oBAAoB,SAAY,EAAE,iBAAiB,MAAM,gBAAgB,IAAI,CAAC;AAAA,IACxF,GAAI,MAAM,2BAA2B,SAAY,EAAE,wBAAwB,MAAM,uBAAuB,IAAI,CAAC;AAAA,IAC7G,GAAI,MAAM,kBAAkB,SAAY,EAAE,eAAe,MAAM,cAAc,IAAI,CAAC;AAAA,EACpF;AACF;","names":[]}
@@ -0,0 +1,7 @@
1
+ import { T as TxResult, c as WalletCapabilities } from './types-CZnHFnQK.js';
2
+
3
+ declare function normalizeTxResult(raw: unknown): TxResult;
4
+
5
+ declare function walletSupportsTypedData(capabilities: Pick<WalletCapabilities, 'signTypedData'>): boolean;
6
+
7
+ export { normalizeTxResult as n, walletSupportsTypedData as w };
@@ -0,0 +1,7 @@
1
+ import { T as TxResult, c as WalletCapabilities } from './types-CZnHFnQK.cjs';
2
+
3
+ declare function normalizeTxResult(raw: unknown): TxResult;
4
+
5
+ declare function walletSupportsTypedData(capabilities: Pick<WalletCapabilities, 'signTypedData'>): boolean;
6
+
7
+ export { normalizeTxResult as n, walletSupportsTypedData as w };
@@ -0,0 +1,277 @@
1
+ import {
2
+ normalizeTxResult
3
+ } from "./chunk-VYEUIAUC.js";
4
+
5
+ // src/provider/tronweb.ts
6
+ import {
7
+ SDKError,
8
+ TRON_ZERO_ADDRESS
9
+ } from "@sun-protocol/sun-sdk-core";
10
+ var DEFAULT_INCLUDED_RECEIPT_TIMEOUT_MS = 45e3;
11
+ var DEFAULT_SOLIDIFIED_RECEIPT_TIMEOUT_MS = 12e4;
12
+ var DEFAULT_RECEIPT_POLL_INTERVAL_MS = 3e3;
13
+ function methodName(functionSelector) {
14
+ return functionSelector.slice(0, functionSelector.indexOf("("));
15
+ }
16
+ function contractMethod(contract, functionSelector) {
17
+ if (typeof contract !== "object" || contract === null) {
18
+ return void 0;
19
+ }
20
+ const record = contract;
21
+ const methods = typeof record.methods === "object" && record.methods !== null ? record.methods : void 0;
22
+ const method = methods?.[functionSelector] ?? record[functionSelector] ?? record[methodName(functionSelector)];
23
+ return typeof method === "function" ? method : void 0;
24
+ }
25
+ function parameterValues(parameters) {
26
+ return parameters?.map((parameter) => parameter.value) ?? [];
27
+ }
28
+ function cloneAbiV2Value(value) {
29
+ if (Array.isArray(value)) {
30
+ return value.map(cloneAbiV2Value);
31
+ }
32
+ if (isPlainObject(value)) {
33
+ return Object.fromEntries(Object.entries(value).map(([key, nestedValue]) => [key, cloneAbiV2Value(nestedValue)]));
34
+ }
35
+ return value;
36
+ }
37
+ function isPlainObject(value) {
38
+ if (typeof value !== "object" || value === null) {
39
+ return false;
40
+ }
41
+ const prototype = Object.getPrototypeOf(value);
42
+ return prototype === Object.prototype || prototype === null;
43
+ }
44
+ function abiV2Options(call) {
45
+ if (!isAbiV2Function(call.abiFunction) || !call.abiFunction.inputs?.some((input) => input.components !== void 0)) {
46
+ return void 0;
47
+ }
48
+ return {
49
+ funcABIV2: call.abiFunction,
50
+ parametersV2: parameterValues(call.parameters).map(cloneAbiV2Value)
51
+ };
52
+ }
53
+ function isAbiV2Function(value) {
54
+ return typeof value === "object" && value !== null && (!("inputs" in value) || Array.isArray(value.inputs));
55
+ }
56
+ function isContractAbiFunction(value) {
57
+ return isAbiV2Function(value) && value.type === "function" && typeof value.name === "string";
58
+ }
59
+ function tronWebCallValue(value) {
60
+ if (value < 0n || value > BigInt(Number.MAX_SAFE_INTEGER)) {
61
+ throw new SDKError("SDK_INVALID_ARGUMENT", "callValue exceeds TronWeb safe integer range", {
62
+ callValue: value.toString(),
63
+ maxSafeInteger: Number.MAX_SAFE_INTEGER
64
+ });
65
+ }
66
+ return Number(value);
67
+ }
68
+ function contractCallOptions(call) {
69
+ return {
70
+ ...call.feeLimit !== void 0 ? { feeLimit: call.feeLimit } : {},
71
+ ...call.callValue !== void 0 ? { callValue: tronWebCallValue(call.callValue) } : {},
72
+ ...call.tokenId !== void 0 ? { tokenId: call.tokenId } : {},
73
+ ...call.tokenValue !== void 0 ? { tokenValue: call.tokenValue } : {},
74
+ ...call.permissionId !== void 0 ? { permissionId: call.permissionId } : {},
75
+ ...call.rawParameter !== void 0 ? { rawParameter: call.rawParameter } : {}
76
+ };
77
+ }
78
+ function unwrapBuiltTransaction(raw) {
79
+ if (raw && typeof raw === "object" && "transaction" in raw) {
80
+ return raw.transaction;
81
+ }
82
+ return raw;
83
+ }
84
+ async function callContractMethod(method, call) {
85
+ const result = method(...parameterValues(call.parameters));
86
+ if (result && typeof result === "object" && "call" in result && typeof result.call === "function") {
87
+ return result.call({ from: call.from ?? TRON_ZERO_ADDRESS });
88
+ }
89
+ return result;
90
+ }
91
+ async function readWithContractAbi(tronWeb, call) {
92
+ let contract;
93
+ try {
94
+ contract = await tronWeb.contract().at(call.target);
95
+ } catch {
96
+ return { found: false };
97
+ }
98
+ const method = contractMethod(contract, call.functionSelector);
99
+ if (!method) {
100
+ return { found: false };
101
+ }
102
+ return { found: true, value: await callContractMethod(method, call) };
103
+ }
104
+ async function readWithProvidedAbi(tronWeb, call) {
105
+ if (!isContractAbiFunction(call.abiFunction)) {
106
+ throw new SDKError("SDK_INVALID_ARGUMENT", `Invalid ABI function for ${call.functionSelector}`, { call });
107
+ }
108
+ const contract = await tronWeb.contract([call.abiFunction], call.target);
109
+ const method = contractMethod(contract, call.functionSelector);
110
+ if (!method) {
111
+ throw new SDKError("SDK_RUNTIME_ERROR", `TronWeb ABI method not found: ${call.functionSelector}`, { call });
112
+ }
113
+ return callContractMethod(method, call);
114
+ }
115
+ function constantResults(result, call) {
116
+ const values = result?.constant_result;
117
+ if (!Array.isArray(values) || !values.every((value) => typeof value === "string")) {
118
+ throw new SDKError("SDK_CONTRACT_ERROR", `Invalid raw constant result for ${call.functionSelector}`, { call, result });
119
+ }
120
+ return values;
121
+ }
122
+ function constantResultHex(result, call) {
123
+ const raw = result?.constant_result?.[0];
124
+ if (typeof raw !== "string" || !/^(0x)?[0-9a-fA-F]*$/.test(raw)) {
125
+ throw new SDKError("SDK_CONTRACT_ERROR", `Invalid constant read result for ${call.functionSelector}`, { call, result });
126
+ }
127
+ return raw.startsWith("0x") ? raw.slice(2) : raw;
128
+ }
129
+ function decodeConstantResult(tronWeb, result, call) {
130
+ const outputs = call.outputs ?? [];
131
+ const hex = constantResultHex(result, call);
132
+ const types = outputs.map((output) => {
133
+ if (!/^(?:u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?|bool|address|bytes32)$/.test(output.type)) {
134
+ throw new SDKError("SDK_RUNTIME_ERROR", `Unsupported constant read output type: ${output.type}`, { output });
135
+ }
136
+ return output.type;
137
+ });
138
+ try {
139
+ const decoded = tronWeb.utils.abi.decodeParams([], types, `0x${hex}`);
140
+ const values = outputs.map((output, index) => {
141
+ const value = decoded[index];
142
+ if (/^u?int/.test(output.type)) return String(value);
143
+ if (output.type === "address") return `0x${String(value).slice(2)}`;
144
+ return value;
145
+ });
146
+ return values.length === 1 ? values[0] : values;
147
+ } catch (cause) {
148
+ throw new SDKError("SDK_CONTRACT_ERROR", `Invalid constant read result for ${call.functionSelector}`, {
149
+ call,
150
+ result,
151
+ cause
152
+ });
153
+ }
154
+ }
155
+ async function readWithConstantSelector(tronWeb, call) {
156
+ const result = await readRawConstant(tronWeb, call);
157
+ return decodeConstantResult(tronWeb, result, call);
158
+ }
159
+ async function readRawConstant(tronWeb, call) {
160
+ const abiV2 = abiV2Options(call);
161
+ const result = await tronWeb.transactionBuilder.triggerConstantContract(
162
+ call.target,
163
+ call.functionSelector,
164
+ {
165
+ ...call.rawParameter !== void 0 ? { rawParameter: call.rawParameter } : {},
166
+ ...abiV2
167
+ },
168
+ abiV2 ? [] : call.parameters ?? [],
169
+ call.from ?? TRON_ZERO_ADDRESS
170
+ );
171
+ return result;
172
+ }
173
+ function transactionReceiptResult(value) {
174
+ if (typeof value !== "object" || value === null) return void 0;
175
+ const record = value;
176
+ const receipt = typeof record.receipt === "object" && record.receipt !== null ? record.receipt : void 0;
177
+ if (typeof receipt?.result === "string") return receipt.result;
178
+ return typeof record.result === "string" ? record.result : void 0;
179
+ }
180
+ function receiptOption(value, fallback, name, allowZero) {
181
+ const resolved = value ?? fallback;
182
+ if (!Number.isFinite(resolved) || !Number.isInteger(resolved) || resolved < (allowZero ? 0 : 1)) {
183
+ throw new SDKError("SDK_INVALID_ARGUMENT", `${name} must be ${allowZero ? "a non-negative" : "a positive"} integer`, {
184
+ [name]: value
185
+ });
186
+ }
187
+ return resolved;
188
+ }
189
+ function receiptFinality(value) {
190
+ if (value === void 0) return "solidified";
191
+ if (value === "included" || value === "solidified") return value;
192
+ throw new SDKError("SDK_INVALID_ARGUMENT", "Unsupported transaction receipt finality", {
193
+ finality: value
194
+ });
195
+ }
196
+ function delay(ms) {
197
+ return new Promise((resolve) => setTimeout(resolve, ms));
198
+ }
199
+ function createTronWebClient(input) {
200
+ return {
201
+ kind: "tronweb",
202
+ network: input.network,
203
+ async getNativeBalance(owner) {
204
+ return String(await input.tronWeb.trx.getBalance(owner));
205
+ },
206
+ async readContract(call) {
207
+ if (call.abiFunction !== void 0) {
208
+ return readWithProvidedAbi(input.tronWeb, call);
209
+ }
210
+ if (call.rawResult) {
211
+ return readRawConstant(input.tronWeb, call);
212
+ }
213
+ if (call.outputs?.length) {
214
+ return readWithConstantSelector(input.tronWeb, call);
215
+ }
216
+ const chainAbiResult = await readWithContractAbi(input.tronWeb, call);
217
+ if (chainAbiResult.found) {
218
+ return chainAbiResult.value;
219
+ }
220
+ return constantResults(await readRawConstant(input.tronWeb, call), call);
221
+ },
222
+ async buildTransaction(call, options = {}) {
223
+ const abiV2 = abiV2Options(call);
224
+ const raw = await input.tronWeb.transactionBuilder.triggerSmartContract(
225
+ call.target,
226
+ call.functionSelector,
227
+ { ...contractCallOptions(call), ...abiV2 },
228
+ abiV2 ? [] : call.parameters ?? [],
229
+ options.ownerAddress
230
+ );
231
+ return unwrapBuiltTransaction(raw);
232
+ },
233
+ async broadcastTransaction(tx) {
234
+ return normalizeTxResult(await input.tronWeb.trx.sendRawTransaction(tx));
235
+ },
236
+ async waitForTransactionReceipt(txid, options = {}) {
237
+ const finality = receiptFinality(options.finality);
238
+ const defaultTimeoutMs = finality === "included" ? DEFAULT_INCLUDED_RECEIPT_TIMEOUT_MS : DEFAULT_SOLIDIFIED_RECEIPT_TIMEOUT_MS;
239
+ const timeoutMs = receiptOption(options.timeoutMs, defaultTimeoutMs, "timeoutMs", true);
240
+ const pollIntervalMs = receiptOption(
241
+ options.pollIntervalMs,
242
+ DEFAULT_RECEIPT_POLL_INTERVAL_MS,
243
+ "pollIntervalMs",
244
+ false
245
+ );
246
+ const deadline = Date.now() + timeoutMs;
247
+ let lastError;
248
+ while (true) {
249
+ try {
250
+ const raw = finality === "included" ? await input.tronWeb.trx.getUnconfirmedTransactionInfo(txid) : await input.tronWeb.trx.getTransactionInfo(txid);
251
+ const result = transactionReceiptResult(raw);
252
+ if (result !== void 0) {
253
+ return { txid, result, success: result === "SUCCESS", raw };
254
+ }
255
+ lastError = void 0;
256
+ } catch (error) {
257
+ lastError = error;
258
+ }
259
+ const remainingMs = deadline - Date.now();
260
+ if (remainingMs <= 0) {
261
+ throw new SDKError("SDK_RUNTIME_ERROR", "Timed out waiting for transaction receipt", {
262
+ txid,
263
+ finality,
264
+ timeoutMs,
265
+ ...lastError !== void 0 ? { cause: lastError } : {}
266
+ });
267
+ }
268
+ await delay(Math.min(pollIntervalMs, remainingMs));
269
+ }
270
+ }
271
+ };
272
+ }
273
+
274
+ export {
275
+ createTronWebClient
276
+ };
277
+ //# sourceMappingURL=chunk-AJSGBCSK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/provider/tronweb.ts"],"sourcesContent":["import {\n SDKError,\n TRON_ZERO_ADDRESS,\n type ContractParameter,\n type Network,\n type TransactionReceiptFinality,\n} from '@sun-protocol/sun-sdk-core'\nimport type { TronWeb } from 'tronweb'\nimport { normalizeTxResult } from '../tx/normalize-result.js'\nimport type {\n BuildTransactionOptions,\n ContractCall,\n ContractRead,\n SignedTronTransaction,\n TransactionReceipt,\n TronClient,\n UnsignedTronTransaction,\n WaitForTransactionReceiptOptions,\n} from '../types.js'\n\nconst DEFAULT_INCLUDED_RECEIPT_TIMEOUT_MS = 45_000\nconst DEFAULT_SOLIDIFIED_RECEIPT_TIMEOUT_MS = 120_000\nconst DEFAULT_RECEIPT_POLL_INTERVAL_MS = 3_000\n\ntype TriggerSmartContractParameters = Parameters<TronWeb['transactionBuilder']['triggerSmartContract']>\ntype TriggerSmartContractOptions = NonNullable<TriggerSmartContractParameters[2]>\ntype TriggerSmartContractArgs = NonNullable<TriggerSmartContractParameters[3]>\ntype TriggerConstantContractParameters = Parameters<TronWeb['transactionBuilder']['triggerConstantContract']>\ntype TriggerConstantContractArgs = NonNullable<TriggerConstantContractParameters[3]>\n\ninterface AbiV2Function {\n readonly type?: string\n readonly name?: string\n readonly inputs?: readonly AbiV2Input[]\n}\n\ninterface AbiV2Input {\n readonly components?: readonly unknown[]\n}\n\ntype AbiV2Options = {\n readonly funcABIV2: AbiV2Function\n readonly parametersV2: readonly unknown[]\n}\n\nexport interface TronWebClientInput {\n readonly network: Network\n readonly tronWeb: TronWeb\n}\n\nfunction methodName(functionSelector: string): string {\n return functionSelector.slice(0, functionSelector.indexOf('('))\n}\n\ntype ContractMethod = (...args: unknown[]) => unknown\n\nfunction contractMethod(contract: unknown, functionSelector: string): ContractMethod | undefined {\n if (typeof contract !== 'object' || contract === null) {\n return undefined\n }\n const record = contract as Record<string, unknown>\n const methods = typeof record.methods === 'object' && record.methods !== null\n ? record.methods as Record<string, unknown>\n : undefined\n const method = methods?.[functionSelector]\n ?? record[functionSelector]\n ?? record[methodName(functionSelector)]\n return typeof method === 'function' ? method as ContractMethod : undefined\n}\n\nfunction parameterValues(parameters: readonly ContractParameter[] | undefined): readonly unknown[] {\n return parameters?.map((parameter) => parameter.value) ?? []\n}\n\nfunction cloneAbiV2Value(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map(cloneAbiV2Value)\n }\n if (isPlainObject(value)) {\n return Object.fromEntries(Object.entries(value).map(([key, nestedValue]) => [key, cloneAbiV2Value(nestedValue)]))\n }\n return value\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null) {\n return false\n }\n const prototype = Object.getPrototypeOf(value)\n return prototype === Object.prototype || prototype === null\n}\n\nfunction abiV2Options(call: ContractRead): AbiV2Options | undefined {\n if (!isAbiV2Function(call.abiFunction) || !call.abiFunction.inputs?.some((input) => input.components !== undefined)) {\n return undefined\n }\n return {\n funcABIV2: call.abiFunction,\n parametersV2: parameterValues(call.parameters).map(cloneAbiV2Value),\n }\n}\n\nfunction isAbiV2Function(value: unknown): value is AbiV2Function {\n return typeof value === 'object' && value !== null\n && (!('inputs' in value) || Array.isArray((value as AbiV2Function).inputs))\n}\n\nfunction isContractAbiFunction(value: unknown): value is AbiV2Function {\n return isAbiV2Function(value)\n && value.type === 'function'\n && typeof value.name === 'string'\n}\n\nfunction tronWebCallValue(value: bigint): number {\n if (value < 0n || value > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new SDKError('SDK_INVALID_ARGUMENT', 'callValue exceeds TronWeb safe integer range', {\n callValue: value.toString(),\n maxSafeInteger: Number.MAX_SAFE_INTEGER,\n })\n }\n return Number(value)\n}\n\nfunction contractCallOptions(call: ContractCall): TriggerSmartContractOptions {\n return {\n ...(call.feeLimit !== undefined ? { feeLimit: call.feeLimit } : {}),\n ...(call.callValue !== undefined ? { callValue: tronWebCallValue(call.callValue) } : {}),\n ...(call.tokenId !== undefined ? { tokenId: call.tokenId } : {}),\n ...(call.tokenValue !== undefined ? { tokenValue: call.tokenValue } : {}),\n ...(call.permissionId !== undefined ? { permissionId: call.permissionId } : {}),\n ...(call.rawParameter !== undefined ? { rawParameter: call.rawParameter } : {}),\n }\n}\n\nfunction unwrapBuiltTransaction(raw: unknown): UnsignedTronTransaction {\n if (raw && typeof raw === 'object' && 'transaction' in raw) {\n return (raw as { transaction: UnsignedTronTransaction }).transaction\n }\n return raw as UnsignedTronTransaction\n}\n\nasync function callContractMethod<T>(method: ContractMethod, call: ContractRead): Promise<T> {\n const result = method(...parameterValues(call.parameters))\n if (result && typeof result === 'object' && 'call' in result && typeof result.call === 'function') {\n return result.call({ from: call.from ?? TRON_ZERO_ADDRESS }) as Promise<T>\n }\n return result as T\n}\n\nasync function readWithContractAbi<T>(tronWeb: TronWeb, call: ContractRead): Promise<{ found: true; value: T } | { found: false }> {\n let contract: unknown\n try {\n contract = await tronWeb.contract().at(call.target)\n } catch {\n return { found: false }\n }\n const method = contractMethod(contract, call.functionSelector)\n if (!method) {\n return { found: false }\n }\n return { found: true, value: await callContractMethod<T>(method, call) }\n}\n\nasync function readWithProvidedAbi<T>(tronWeb: TronWeb, call: ContractRead): Promise<T> {\n if (!isContractAbiFunction(call.abiFunction)) {\n throw new SDKError('SDK_INVALID_ARGUMENT', `Invalid ABI function for ${call.functionSelector}`, { call })\n }\n const contract = await tronWeb.contract([call.abiFunction] as never, call.target)\n const method = contractMethod(contract, call.functionSelector)\n if (!method) {\n throw new SDKError('SDK_RUNTIME_ERROR', `TronWeb ABI method not found: ${call.functionSelector}`, { call })\n }\n return callContractMethod<T>(method, call)\n}\n\nfunction constantResults(result: unknown, call: ContractRead): readonly string[] {\n const values = (result as { readonly constant_result?: readonly unknown[] } | null)?.constant_result\n if (!Array.isArray(values) || !values.every((value) => typeof value === 'string')) {\n throw new SDKError('SDK_CONTRACT_ERROR', `Invalid raw constant result for ${call.functionSelector}`, { call, result })\n }\n return values as readonly string[]\n}\n\nfunction constantResultHex(result: unknown, call: ContractRead): string {\n const raw = (result as { readonly constant_result?: readonly unknown[] } | null)?.constant_result?.[0]\n if (typeof raw !== 'string' || !/^(0x)?[0-9a-fA-F]*$/.test(raw)) {\n throw new SDKError('SDK_CONTRACT_ERROR', `Invalid constant read result for ${call.functionSelector}`, { call, result })\n }\n return raw.startsWith('0x') ? raw.slice(2) : raw\n}\n\nfunction decodeConstantResult(tronWeb: TronWeb, result: unknown, call: ContractRead): unknown {\n const outputs = call.outputs ?? []\n const hex = constantResultHex(result, call)\n const types = outputs.map((output) => {\n // Keep the selector API's existing supported types; TronWeb owns ABI decoding.\n if (!/^(?:u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?|bool|address|bytes32)$/.test(output.type)) {\n throw new SDKError('SDK_RUNTIME_ERROR', `Unsupported constant read output type: ${output.type}`, { output })\n }\n return output.type\n })\n\n try {\n const decoded = tronWeb.utils.abi.decodeParams([], types, `0x${hex}`) as unknown[]\n const values = outputs.map((output, index) => {\n const value = decoded[index]\n // Preserve SDK decimal strings and 20-byte hex addresses.\n if (/^u?int/.test(output.type)) return String(value)\n if (output.type === 'address') return `0x${String(value).slice(2)}`\n return value\n })\n return values.length === 1 ? values[0] : values\n } catch (cause) {\n throw new SDKError('SDK_CONTRACT_ERROR', `Invalid constant read result for ${call.functionSelector}`, {\n call, result, cause,\n })\n }\n}\n\nasync function readWithConstantSelector<T>(tronWeb: TronWeb, call: ContractRead): Promise<T> {\n const result = await readRawConstant(tronWeb, call)\n return decodeConstantResult(tronWeb, result, call) as T\n}\n\nasync function readRawConstant(tronWeb: TronWeb, call: ContractRead): Promise<unknown> {\n const abiV2 = abiV2Options(call)\n const result = await tronWeb.transactionBuilder.triggerConstantContract(\n call.target,\n call.functionSelector,\n {\n ...(call.rawParameter !== undefined ? { rawParameter: call.rawParameter } : {}),\n ...abiV2,\n } as TriggerConstantContractParameters[2],\n (abiV2 ? [] : call.parameters ?? []) as TriggerConstantContractArgs,\n call.from ?? TRON_ZERO_ADDRESS,\n )\n return result\n}\n\nfunction transactionReceiptResult(value: unknown): string | undefined {\n if (typeof value !== 'object' || value === null) return undefined\n const record = value as Record<string, unknown>\n const receipt = typeof record.receipt === 'object' && record.receipt !== null\n ? record.receipt as Record<string, unknown>\n : undefined\n if (typeof receipt?.result === 'string') return receipt.result\n return typeof record.result === 'string' ? record.result : undefined\n}\n\nfunction receiptOption(value: number | undefined, fallback: number, name: string, allowZero: boolean): number {\n const resolved = value ?? fallback\n if (!Number.isFinite(resolved) || !Number.isInteger(resolved) || resolved < (allowZero ? 0 : 1)) {\n throw new SDKError('SDK_INVALID_ARGUMENT', `${name} must be ${allowZero ? 'a non-negative' : 'a positive'} integer`, {\n [name]: value,\n })\n }\n return resolved\n}\n\nfunction receiptFinality(value: unknown): TransactionReceiptFinality {\n if (value === undefined) return 'solidified'\n if (value === 'included' || value === 'solidified') return value\n throw new SDKError('SDK_INVALID_ARGUMENT', 'Unsupported transaction receipt finality', {\n finality: value,\n })\n}\n\nfunction delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n\nexport function createTronWebClient(input: TronWebClientInput): TronClient {\n return {\n kind: 'tronweb',\n network: input.network,\n async getNativeBalance(owner) {\n return String(await input.tronWeb.trx.getBalance(owner))\n },\n async readContract<T = unknown>(call: ContractRead): Promise<T> {\n if (call.abiFunction !== undefined) {\n return readWithProvidedAbi<T>(input.tronWeb, call)\n }\n if (call.rawResult) {\n return readRawConstant(input.tronWeb, call) as Promise<T>\n }\n if (call.outputs?.length) {\n return readWithConstantSelector<T>(input.tronWeb, call)\n }\n const chainAbiResult = await readWithContractAbi<T>(input.tronWeb, call)\n if (chainAbiResult.found) {\n return chainAbiResult.value\n }\n return constantResults(await readRawConstant(input.tronWeb, call), call) as T\n },\n async buildTransaction(call: ContractCall, options: BuildTransactionOptions = {}): Promise<UnsignedTronTransaction> {\n const abiV2 = abiV2Options(call)\n const raw = await input.tronWeb.transactionBuilder.triggerSmartContract(\n call.target,\n call.functionSelector,\n { ...contractCallOptions(call), ...abiV2 } as TriggerSmartContractOptions,\n (abiV2 ? [] : call.parameters ?? []) as TriggerSmartContractArgs,\n options.ownerAddress,\n )\n return unwrapBuiltTransaction(raw)\n },\n async broadcastTransaction(tx: SignedTronTransaction) {\n return normalizeTxResult(await input.tronWeb.trx.sendRawTransaction(tx as Parameters<TronWeb['trx']['sendRawTransaction']>[0]))\n },\n async waitForTransactionReceipt(\n txid: string,\n options: WaitForTransactionReceiptOptions = {},\n ): Promise<TransactionReceipt> {\n const finality = receiptFinality(options.finality)\n const defaultTimeoutMs = finality === 'included'\n ? DEFAULT_INCLUDED_RECEIPT_TIMEOUT_MS\n : DEFAULT_SOLIDIFIED_RECEIPT_TIMEOUT_MS\n const timeoutMs = receiptOption(options.timeoutMs, defaultTimeoutMs, 'timeoutMs', true)\n const pollIntervalMs = receiptOption(\n options.pollIntervalMs,\n DEFAULT_RECEIPT_POLL_INTERVAL_MS,\n 'pollIntervalMs',\n false,\n )\n const deadline = Date.now() + timeoutMs\n let lastError: unknown\n\n while (true) {\n try {\n // FullNode exposes the latest included/executed receipt. SolidityNode\n // exposes only solidified (irreversible) receipts and therefore lags.\n const raw = finality === 'included'\n ? await input.tronWeb.trx.getUnconfirmedTransactionInfo(txid)\n : await input.tronWeb.trx.getTransactionInfo(txid)\n const result = transactionReceiptResult(raw)\n if (result !== undefined) {\n return { txid, result, success: result === 'SUCCESS', raw }\n }\n lastError = undefined\n } catch (error) {\n lastError = error\n }\n\n const remainingMs = deadline - Date.now()\n if (remainingMs <= 0) {\n throw new SDKError('SDK_RUNTIME_ERROR', 'Timed out waiting for transaction receipt', {\n txid,\n finality,\n timeoutMs,\n ...(lastError !== undefined ? { cause: lastError } : {}),\n })\n }\n await delay(Math.min(pollIntervalMs, remainingMs))\n }\n },\n }\n}\n"],"mappings":";;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAcP,IAAM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ACA,UAA4C,CAAC,GAChB;AAC7B,YAAM,WAAW,gBAAgB,QAAQ,QAAQ;AACjD,YAAM,mBAAmB,aAAa,aAClC,sCACA;AACJ,YAAM,YAAY,cAAc,QAAQ,WAAW,kBAAkB,aAAa,IAAI;AACtF,YAAM,iBAAiB;AAAA,QACrB,QAAQ;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,YAAM,WAAW,KAAK,IAAI,IAAI;AAC9B,UAAI;AAEJ,aAAO,MAAM;AACX,YAAI;AAGF,gBAAM,MAAM,aAAa,aACrB,MAAM,MAAM,QAAQ,IAAI,8BAA8B,IAAI,IAC1D,MAAM,MAAM,QAAQ,IAAI,mBAAmB,IAAI;AACnD,gBAAM,SAAS,yBAAyB,GAAG;AAC3C,cAAI,WAAW,QAAW;AACxB,mBAAO,EAAE,MAAM,QAAQ,SAAS,WAAW,WAAW,IAAI;AAAA,UAC5D;AACA,sBAAY;AAAA,QACd,SAAS,OAAO;AACd,sBAAY;AAAA,QACd;AAEA,cAAM,cAAc,WAAW,KAAK,IAAI;AACxC,YAAI,eAAe,GAAG;AACpB,gBAAM,IAAI,SAAS,qBAAqB,6CAA6C;AAAA,YACnF;AAAA,YACA;AAAA,YACA;AAAA,YACA,GAAI,cAAc,SAAY,EAAE,OAAO,UAAU,IAAI,CAAC;AAAA,UACxD,CAAC;AAAA,QACH;AACA,cAAM,MAAM,KAAK,IAAI,gBAAgB,WAAW,CAAC;AAAA,MACnD;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,9 @@
1
+ // src/wallets/capabilities.ts
2
+ function walletSupportsTypedData(capabilities) {
3
+ return capabilities.signTypedData === true;
4
+ }
5
+
6
+ export {
7
+ walletSupportsTypedData
8
+ };
9
+ //# sourceMappingURL=chunk-NVRQ3Z7L.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/wallets/capabilities.ts"],"sourcesContent":["import type { WalletCapabilities } from '../types.js'\n\nexport function walletSupportsTypedData(capabilities: Pick<WalletCapabilities, 'signTypedData'>): boolean {\n return capabilities.signTypedData === true\n}\n"],"mappings":";AAEO,SAAS,wBAAwB,cAAkE;AACxG,SAAO,aAAa,kBAAkB;AACxC;","names":[]}
@@ -0,0 +1,42 @@
1
+ // src/tx/normalize-result.ts
2
+ import { SDKError } from "@sun-protocol/sun-sdk-core";
3
+ function readTxid(value) {
4
+ if (typeof value === "string" && value.length > 0) {
5
+ return value;
6
+ }
7
+ if (!value || typeof value !== "object") {
8
+ return null;
9
+ }
10
+ const record = value;
11
+ const direct = record.txid ?? record.txID ?? record.transactionId ?? record.txHash;
12
+ if (typeof direct === "string" && direct.length > 0) {
13
+ return direct;
14
+ }
15
+ const transaction = record.transaction;
16
+ if (transaction && typeof transaction === "object") {
17
+ return readTxid(transaction);
18
+ }
19
+ return null;
20
+ }
21
+ function hasBroadcastFailure(value) {
22
+ if (!value || typeof value !== "object") {
23
+ return false;
24
+ }
25
+ const record = value;
26
+ return record.result === false || typeof record.code === "string" || typeof record.Error === "string";
27
+ }
28
+ function normalizeTxResult(raw) {
29
+ if (hasBroadcastFailure(raw)) {
30
+ throw new SDKError("SDK_RUNTIME_ERROR", "Transaction broadcast failed", { raw });
31
+ }
32
+ const txid = readTxid(raw);
33
+ if (!txid) {
34
+ throw new SDKError("SDK_RUNTIME_ERROR", "Unable to find txid in transaction result", { raw });
35
+ }
36
+ return { txid, raw };
37
+ }
38
+
39
+ export {
40
+ normalizeTxResult
41
+ };
42
+ //# sourceMappingURL=chunk-VYEUIAUC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/tx/normalize-result.ts"],"sourcesContent":["import { SDKError } from '@sun-protocol/sun-sdk-core'\nimport type { TxResult } from '../types.js'\n\nfunction readTxid(value: unknown): string | null {\n if (typeof value === 'string' && value.length > 0) {\n return value\n }\n\n if (!value || typeof value !== 'object') {\n return null\n }\n\n const record = value as Record<string, unknown>\n const direct = record.txid ?? record.txID ?? record.transactionId ?? record.txHash\n if (typeof direct === 'string' && direct.length > 0) {\n return direct\n }\n\n const transaction = record.transaction\n if (transaction && typeof transaction === 'object') {\n return readTxid(transaction)\n }\n\n return null\n}\n\nfunction hasBroadcastFailure(value: unknown): boolean {\n if (!value || typeof value !== 'object') {\n return false\n }\n\n const record = value as Record<string, unknown>\n return record.result === false || typeof record.code === 'string' || typeof record.Error === 'string'\n}\n\nexport function normalizeTxResult(raw: unknown): TxResult {\n if (hasBroadcastFailure(raw)) {\n throw new SDKError('SDK_RUNTIME_ERROR', 'Transaction broadcast failed', { raw })\n }\n\n const txid = readTxid(raw)\n if (!txid) {\n throw new SDKError('SDK_RUNTIME_ERROR', 'Unable to find txid in transaction result', { raw })\n }\n return { txid, raw }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAGzB,SAAS,SAAS,OAA+B;AAC/C,MAAI,OAAO,UAAU,YAAY,MAAM,SAAS,GAAG;AACjD,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,SAAS,OAAO,UAAU,UAAU;AACvC,WAAO;AAAA,EACT;AAEA,QAAM,SAAS;AACf,QAAM,SAAS,OAAO,QAAQ,OAAO,QAAQ,OAAO,iBAAiB,OAAO;AAC5E,MAAI,OAAO,WAAW,YAAY,OAAO,SAAS,GAAG;AACnD,WAAO;AAAA,EACT;AAEA,QAAM,cAAc,OAAO;AAC3B,MAAI,eAAe,OAAO,gBAAgB,UAAU;AAClD,WAAO,SAAS,WAAW;AAAA,EAC7B;AAEA,SAAO;AACT;AAEA,SAAS,oBAAoB,OAAyB;AACpD,MAAI,CAAC,SAAS,OAAO,UAAU,UAAU;AACvC,WAAO;AAAA,EACT;AAEA,QAAM,SAAS;AACf,SAAO,OAAO,WAAW,SAAS,OAAO,OAAO,SAAS,YAAY,OAAO,OAAO,UAAU;AAC/F;AAEO,SAAS,kBAAkB,KAAwB;AACxD,MAAI,oBAAoB,GAAG,GAAG;AAC5B,UAAM,IAAI,SAAS,qBAAqB,gCAAgC,EAAE,IAAI,CAAC;AAAA,EACjF;AAEA,QAAM,OAAO,SAAS,GAAG;AACzB,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,SAAS,qBAAqB,6CAA6C,EAAE,IAAI,CAAC;AAAA,EAC9F;AACA,SAAO,EAAE,MAAM,IAAI;AACrB;","names":[]}