@ironwallet/mcp-server 1.0.0-preprod.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 (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +161 -0
  3. package/assets/knight.png +0 -0
  4. package/assets/wordmark.svg +20 -0
  5. package/dist/api/auth.d.ts +20 -0
  6. package/dist/api/auth.js +92 -0
  7. package/dist/api/auth.js.map +1 -0
  8. package/dist/api/balances.d.ts +25 -0
  9. package/dist/api/balances.js +565 -0
  10. package/dist/api/balances.js.map +1 -0
  11. package/dist/api/http.d.ts +34 -0
  12. package/dist/api/http.js +277 -0
  13. package/dist/api/http.js.map +1 -0
  14. package/dist/api/relay.d.ts +49 -0
  15. package/dist/api/relay.js +194 -0
  16. package/dist/api/relay.js.map +1 -0
  17. package/dist/api/rpc.d.ts +10 -0
  18. package/dist/api/rpc.js +26 -0
  19. package/dist/api/rpc.js.map +1 -0
  20. package/dist/api/swap.d.ts +134 -0
  21. package/dist/api/swap.js +554 -0
  22. package/dist/api/swap.js.map +1 -0
  23. package/dist/cli.d.ts +6 -0
  24. package/dist/cli.js +20 -0
  25. package/dist/cli.js.map +1 -0
  26. package/dist/config.d.ts +91 -0
  27. package/dist/config.js +175 -0
  28. package/dist/config.js.map +1 -0
  29. package/dist/generated/env-config.d.ts +5 -0
  30. package/dist/generated/env-config.js +23 -0
  31. package/dist/generated/env-config.js.map +1 -0
  32. package/dist/generated/env-profile.d.ts +15 -0
  33. package/dist/generated/env-profile.js +2 -0
  34. package/dist/generated/env-profile.js.map +1 -0
  35. package/dist/keystore/crypto.d.ts +17 -0
  36. package/dist/keystore/crypto.js +57 -0
  37. package/dist/keystore/crypto.js.map +1 -0
  38. package/dist/keystore/store.d.ts +45 -0
  39. package/dist/keystore/store.js +224 -0
  40. package/dist/keystore/store.js.map +1 -0
  41. package/dist/keystore/types.d.ts +31 -0
  42. package/dist/keystore/types.js +2 -0
  43. package/dist/keystore/types.js.map +1 -0
  44. package/dist/local-secrets.d.ts +16 -0
  45. package/dist/local-secrets.js +73 -0
  46. package/dist/local-secrets.js.map +1 -0
  47. package/dist/log.d.ts +30 -0
  48. package/dist/log.js +323 -0
  49. package/dist/log.js.map +1 -0
  50. package/dist/passphrase.d.ts +6 -0
  51. package/dist/passphrase.js +10 -0
  52. package/dist/passphrase.js.map +1 -0
  53. package/dist/policy.d.ts +22 -0
  54. package/dist/policy.js +108 -0
  55. package/dist/policy.js.map +1 -0
  56. package/dist/server.d.ts +6 -0
  57. package/dist/server.js +38 -0
  58. package/dist/server.js.map +1 -0
  59. package/dist/signing/bitcoin.d.ts +18 -0
  60. package/dist/signing/bitcoin.js +84 -0
  61. package/dist/signing/bitcoin.js.map +1 -0
  62. package/dist/signing/dispatch.d.ts +7 -0
  63. package/dist/signing/dispatch.js +35 -0
  64. package/dist/signing/dispatch.js.map +1 -0
  65. package/dist/signing/evm.d.ts +16 -0
  66. package/dist/signing/evm.js +59 -0
  67. package/dist/signing/evm.js.map +1 -0
  68. package/dist/signing/index.d.ts +10 -0
  69. package/dist/signing/index.js +57 -0
  70. package/dist/signing/index.js.map +1 -0
  71. package/dist/signing/solana.d.ts +18 -0
  72. package/dist/signing/solana.js +106 -0
  73. package/dist/signing/solana.js.map +1 -0
  74. package/dist/signing/swap.d.ts +10 -0
  75. package/dist/signing/swap.js +114 -0
  76. package/dist/signing/swap.js.map +1 -0
  77. package/dist/signing/ton.d.ts +33 -0
  78. package/dist/signing/ton.js +166 -0
  79. package/dist/signing/ton.js.map +1 -0
  80. package/dist/signing/tron.d.ts +11 -0
  81. package/dist/signing/tron.js +39 -0
  82. package/dist/signing/tron.js.map +1 -0
  83. package/dist/signing/types.d.ts +23 -0
  84. package/dist/signing/types.js +2 -0
  85. package/dist/signing/types.js.map +1 -0
  86. package/dist/signing/xrp.d.ts +11 -0
  87. package/dist/signing/xrp.js +122 -0
  88. package/dist/signing/xrp.js.map +1 -0
  89. package/dist/tools/helpers.d.ts +42 -0
  90. package/dist/tools/helpers.js +80 -0
  91. package/dist/tools/helpers.js.map +1 -0
  92. package/dist/tools/index.d.ts +7 -0
  93. package/dist/tools/index.js +16 -0
  94. package/dist/tools/index.js.map +1 -0
  95. package/dist/tools/swap.d.ts +6 -0
  96. package/dist/tools/swap.js +343 -0
  97. package/dist/tools/swap.js.map +1 -0
  98. package/dist/tools/transfer.d.ts +6 -0
  99. package/dist/tools/transfer.js +284 -0
  100. package/dist/tools/transfer.js.map +1 -0
  101. package/dist/tools/wallets.d.ts +6 -0
  102. package/dist/tools/wallets.js +79 -0
  103. package/dist/tools/wallets.js.map +1 -0
  104. package/dist/wallet/derive.d.ts +53 -0
  105. package/dist/wallet/derive.js +233 -0
  106. package/dist/wallet/derive.js.map +1 -0
  107. package/dist/web/manager.d.ts +15 -0
  108. package/dist/web/manager.js +444 -0
  109. package/dist/web/manager.js.map +1 -0
  110. package/package.json +54 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitcoin.js","sourceRoot":"","sources":["../../src/signing/bitcoin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAYpC,SAAS,UAAU,CAAC,CAAS;IAC3B,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,GAAgB,EAChB,GAAwB;IAExB,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,GAAgB,EAChB,GAAwB;IAExB,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,CAA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Per-network signing dispatch shared by transfer (`signForward`) and swap
3
+ * (`signSwapTransactions`).
4
+ */
5
+ import { type NetworkId } from "../config.js";
6
+ import type { SignContext, SignedTransaction, TransactionToSign } from "./types.js";
7
+ export declare function dispatchSign(network: NetworkId, ctx: SignContext, txs: TransactionToSign[]): Promise<SignedTransaction[]>;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Per-network signing dispatch shared by transfer (`signForward`) and swap
3
+ * (`signSwapTransactions`).
4
+ */
5
+ import { isEvmNetwork } from "../config.js";
6
+ import { signEvm } from "./evm.js";
7
+ import { signTron } from "./tron.js";
8
+ import { signBitcoin, signDoge, signLitecoin } from "./bitcoin.js";
9
+ import { signSolana } from "./solana.js";
10
+ import { signXrp } from "./xrp.js";
11
+ import { signTon } from "./ton.js";
12
+ export async function dispatchSign(network, ctx, txs) {
13
+ if (isEvmNetwork(network)) {
14
+ return signEvm(network, ctx, txs);
15
+ }
16
+ switch (network) {
17
+ case "tron":
18
+ return signTron(ctx, txs);
19
+ case "bitcoin":
20
+ return signBitcoin(ctx, txs);
21
+ case "litecoin":
22
+ return signLitecoin(ctx, txs);
23
+ case "doge":
24
+ return signDoge(ctx, txs);
25
+ case "solana":
26
+ return signSolana(ctx, txs);
27
+ case "xrp":
28
+ return signXrp(ctx, txs);
29
+ case "ton":
30
+ return signTon(ctx, txs);
31
+ default:
32
+ throw new Error(`Signing is not supported on "${network}".`);
33
+ }
34
+ }
35
+ //# sourceMappingURL=dispatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../src/signing/dispatch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAkB,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGnC,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAAkB,EAClB,GAAgB,EAChB,GAAwB;IAExB,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,OAAO,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IACpC,CAAC;IACD,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC5B,KAAK,SAAS;YACZ,OAAO,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC/B,KAAK,UAAU;YACb,OAAO,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAChC,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC5B,KAAK,QAAQ;YACX,OAAO,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC9B,KAAK,KAAK;YACR,OAAO,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC3B,KAAK,KAAK;YACR,OAAO,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC3B;YACE,MAAM,IAAI,KAAK,CAAC,gCAAgC,OAAiB,IAAI,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * EVM forward signing, matching the mobile app's `forwardToTransferRelay`:
3
+ *
4
+ * 1. Parse `txData` as a serialized UNSIGNED transaction (RLP; typed 0x02 for
5
+ * EIP-1559).
6
+ * 2. Override nonce: start from on-chain getTransactionCount(address),
7
+ * increment per transaction in the batch.
8
+ * 3. Use a live chainId from the RPC node.
9
+ * 4. Sign. ethers serializes typed transactions with their type prefix byte
10
+ * included, matching the app's manual 0x02 prepend.
11
+ * 5. Response: `signature` = full signed serialized tx hex, `txData` = the
12
+ * original unsigned txData unchanged.
13
+ */
14
+ import type { NetworkId } from "../config.js";
15
+ import type { SignContext, SignedTransaction, TransactionToSign } from "./types.js";
16
+ export declare function signEvm(network: NetworkId, ctx: SignContext, txs: TransactionToSign[]): Promise<SignedTransaction[]>;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * EVM forward signing, matching the mobile app's `forwardToTransferRelay`:
3
+ *
4
+ * 1. Parse `txData` as a serialized UNSIGNED transaction (RLP; typed 0x02 for
5
+ * EIP-1559).
6
+ * 2. Override nonce: start from on-chain getTransactionCount(address),
7
+ * increment per transaction in the batch.
8
+ * 3. Use a live chainId from the RPC node.
9
+ * 4. Sign. ethers serializes typed transactions with their type prefix byte
10
+ * included, matching the app's manual 0x02 prepend.
11
+ * 5. Response: `signature` = full signed serialized tx hex, `txData` = the
12
+ * original unsigned txData unchanged.
13
+ */
14
+ import { Transaction, Wallet } from "ethers";
15
+ import { providerFor } from "../api/rpc.js";
16
+ import { logInfo } from "../log.js";
17
+ export async function signEvm(network, ctx, txs) {
18
+ const provider = providerFor(network);
19
+ const wallet = new Wallet(ctx.privateKey);
20
+ const [chainId, startNonce] = await Promise.all([
21
+ provider.getNetwork().then((n) => n.chainId),
22
+ provider.getTransactionCount(ctx.address, "latest"),
23
+ ]);
24
+ logInfo("sign.evm.context", {
25
+ network,
26
+ address: ctx.address,
27
+ chainId: chainId.toString(),
28
+ startNonce,
29
+ txCount: txs.length,
30
+ });
31
+ let nonce = startNonce;
32
+ const signed = [];
33
+ for (const item of txs) {
34
+ if (!item.txData)
35
+ throw new Error("EVM transactionToSign has no txData.");
36
+ const tx = Transaction.from(item.txData);
37
+ tx.nonce = nonce++;
38
+ tx.chainId = chainId;
39
+ const serialized = await wallet.signTransaction(tx);
40
+ logInfo("sign.evm.tx", {
41
+ network,
42
+ transactionId: item.transactionId,
43
+ nonce: tx.nonce,
44
+ chainId: chainId.toString(),
45
+ type: tx.type,
46
+ to: tx.to,
47
+ value: tx.value?.toString(),
48
+ signedLen: serialized.length,
49
+ });
50
+ signed.push({
51
+ signature: serialized,
52
+ txData: item.txData,
53
+ txID: item.txId ?? "",
54
+ transactionId: item.transactionId,
55
+ });
56
+ }
57
+ return signed;
58
+ }
59
+ //# sourceMappingURL=evm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evm.js","sourceRoot":"","sources":["../../src/signing/evm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,OAAkB,EAClB,GAAgB,EAChB,GAAwB;IAExB,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAE1C,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC9C,QAAQ,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QAC5C,QAAQ,CAAC,mBAAmB,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC;KACpD,CAAC,CAAC;IACH,OAAO,CAAC,kBAAkB,EAAE;QAC1B,OAAO;QACP,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE;QAC3B,UAAU;QACV,OAAO,EAAE,GAAG,CAAC,MAAM;KACpB,CAAC,CAAC;IAEH,IAAI,KAAK,GAAG,UAAU,CAAC;IACvB,MAAM,MAAM,GAAwB,EAAE,CAAC;IAEvC,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;QAC1E,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzC,EAAE,CAAC,KAAK,GAAG,KAAK,EAAE,CAAC;QACnB,EAAE,CAAC,OAAO,GAAG,OAAO,CAAC;QACrB,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;QACpD,OAAO,CAAC,aAAa,EAAE;YACrB,OAAO;YACP,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,KAAK,EAAE,EAAE,CAAC,KAAK;YACf,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE;YAC3B,IAAI,EAAE,EAAE,CAAC,IAAI;YACb,EAAE,EAAE,EAAE,CAAC,EAAE;YACT,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE;YAC3B,SAAS,EAAE,UAAU,CAAC,MAAM;SAC7B,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC;YACV,SAAS,EAAE,UAAU;YACrB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE;YACrB,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /** Signer registry: dispatch to the per-network implementation. */
2
+ import type { NetworkId } from "../config.js";
3
+ import type { SignedTransaction, TransactionToSign } from "./types.js";
4
+ export type { SignedTransaction, TransactionToSign } from "./types.js";
5
+ export { dispatchSign } from "./dispatch.js";
6
+ /**
7
+ * Derive the key for `network` from the mnemonic and sign every transaction.
8
+ * The mnemonic stays inside this call; only signatures are returned.
9
+ */
10
+ export declare function signForward(network: NetworkId, mnemonic: string, txs: TransactionToSign[]): Promise<SignedTransaction[]>;
@@ -0,0 +1,57 @@
1
+ /** Signer registry: dispatch to the per-network implementation. */
2
+ import { deriveKey } from "../wallet/derive.js";
3
+ import { dispatchSign } from "./dispatch.js";
4
+ import { logError, logInfo } from "../log.js";
5
+ export { dispatchSign } from "./dispatch.js";
6
+ /**
7
+ * Derive the key for `network` from the mnemonic and sign every transaction.
8
+ * The mnemonic stays inside this call; only signatures are returned.
9
+ */
10
+ export async function signForward(network, mnemonic, txs) {
11
+ const started = Date.now();
12
+ const { privateKey, address } = deriveKey(mnemonic, network);
13
+ const ctx = { privateKey, address };
14
+ logInfo("sign.start", {
15
+ network,
16
+ address,
17
+ txCount: txs.length,
18
+ txs: txs.map((t, i) => ({
19
+ i,
20
+ transactionId: t.transactionId,
21
+ txId: t.txId,
22
+ type: t.type,
23
+ hasTxData: Boolean(t.txData),
24
+ txDataLen: t.txData?.length,
25
+ hasExtraData: Boolean(t.extraData),
26
+ extraDataLen: t.extraData?.length,
27
+ value: t.value,
28
+ })),
29
+ });
30
+ try {
31
+ const signed = await dispatchSign(network, ctx, txs);
32
+ logInfo("sign.ok", {
33
+ network,
34
+ address,
35
+ elapsedMs: Date.now() - started,
36
+ signedCount: signed.length,
37
+ signed: signed.map((t, i) => ({
38
+ i,
39
+ transactionId: t.transactionId,
40
+ txID: t.txID,
41
+ signatureLen: t.signature?.length,
42
+ txDataLen: t.txData?.length,
43
+ })),
44
+ });
45
+ return signed;
46
+ }
47
+ catch (e) {
48
+ logError("sign.fail", e, {
49
+ network,
50
+ address,
51
+ txCount: txs.length,
52
+ elapsedMs: Date.now() - started,
53
+ });
54
+ throw e;
55
+ }
56
+ }
57
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/signing/index.ts"],"names":[],"mappings":"AAAA,mEAAmE;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P,OAAO;YACP,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO;YAC/B,WAAW,EAAE,MAAM,CAAC,MAAM;YAC1B,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC5B,CAAC;gBACD,aAAa,EAAE,CAAC,CAAC,aAAa;gBAC9B,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,YAAY,EAAE,CAAC,CAAC,SAAS,EAAE,MAAM;gBACjC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM;aAC5B,CAAC,CAAC;SACJ,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,QAAQ,CAAC,WAAW,EAAE,CAAC,EAAE;YACvB,OAAO;YACP,OAAO;YACP,OAAO,EAAE,GAAG,CAAC,MAAM;YACnB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO;SAChC,CAAC,CAAC;QACH,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Solana forward signing, matching the mobile app's relay path
3
+ * (solana_net_api_client.forwardToTransferRelay):
4
+ *
5
+ * - `txData` = the serialized *compiled message* bytes (hex, optional 0x). It is
6
+ * a message only, not a full transaction (no signatures yet).
7
+ * - Before signing, the mobile client fetches a fresh `latestBlockhash` and
8
+ * swaps it into the message, then ed25519-signs the message bytes.
9
+ * - The forward request carries the *entire* signed transaction wire bytes as
10
+ * hex in `signature` ([compact-u16 numSigs][sigs][message]), the base58 first
11
+ * signature in `txID`, and the original estimate `txData` (unchanged).
12
+ *
13
+ * We only support single-signer transfers (the fee payer, account index 0, is the
14
+ * wallet). The recent blockhash sits right after the static account keys in both
15
+ * legacy and v0 messages, so the swap works for either.
16
+ */
17
+ import type { SignContext, SignedTransaction, TransactionToSign } from "./types.js";
18
+ export declare function signSolana(ctx: SignContext, txs: TransactionToSign[]): Promise<SignedTransaction[]>;
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Solana forward signing, matching the mobile app's relay path
3
+ * (solana_net_api_client.forwardToTransferRelay):
4
+ *
5
+ * - `txData` = the serialized *compiled message* bytes (hex, optional 0x). It is
6
+ * a message only, not a full transaction (no signatures yet).
7
+ * - Before signing, the mobile client fetches a fresh `latestBlockhash` and
8
+ * swaps it into the message, then ed25519-signs the message bytes.
9
+ * - The forward request carries the *entire* signed transaction wire bytes as
10
+ * hex in `signature` ([compact-u16 numSigs][sigs][message]), the base58 first
11
+ * signature in `txID`, and the original estimate `txData` (unchanged).
12
+ *
13
+ * We only support single-signer transfers (the fee payer, account index 0, is the
14
+ * wallet). The recent blockhash sits right after the static account keys in both
15
+ * legacy and v0 messages, so the swap works for either.
16
+ */
17
+ import bs58 from "bs58";
18
+ import { ed25519 } from "@noble/curves/ed25519.js";
19
+ import { getConfig } from "../config.js";
20
+ import { httpJson } from "../api/http.js";
21
+ import { logInfo } from "../log.js";
22
+ function hexToBytes(h) {
23
+ return Uint8Array.from(Buffer.from(h.replace(/^0x/, ""), "hex"));
24
+ }
25
+ /** Decode a Solana compact-u16 (shortvec) length. Returns [value, bytesRead]. */
26
+ function decodeCompactU16(buf, offset) {
27
+ let value = 0;
28
+ let read = 0;
29
+ for (;;) {
30
+ const byte = buf[offset + read];
31
+ value |= (byte & 0x7f) << (read * 7);
32
+ read++;
33
+ if ((byte & 0x80) === 0)
34
+ break;
35
+ if (read > 3)
36
+ throw new Error("Invalid compact-u16 in Solana message.");
37
+ }
38
+ return [value >>> 0, read];
39
+ }
40
+ async function latestBlockhash() {
41
+ const cfg = getConfig();
42
+ const res = await httpJson(cfg.solanaRpcUrl, {
43
+ method: "POST",
44
+ headers: { "Content-Type": "application/json" },
45
+ body: JSON.stringify({
46
+ jsonrpc: "2.0",
47
+ id: 1,
48
+ method: "getLatestBlockhash",
49
+ params: [{ commitment: "finalized" }],
50
+ }),
51
+ }, { retry: true });
52
+ const bh = res.result?.value?.blockhash;
53
+ if (!bh)
54
+ throw new Error("Failed to fetch Solana latest blockhash.");
55
+ return bs58.decode(bh);
56
+ }
57
+ /** Locate the 32-byte recent-blockhash offset within a compiled message. */
58
+ function blockhashOffset(msg) {
59
+ const versioned = (msg[0] & 0x80) !== 0;
60
+ const headerStart = versioned ? 1 : 0;
61
+ const numSigners = msg[headerStart];
62
+ const keysCountAt = headerStart + 3; // after the 3 header bytes
63
+ const [numKeys, read] = decodeCompactU16(msg, keysCountAt);
64
+ return { offset: keysCountAt + read + numKeys * 32, numSigners };
65
+ }
66
+ export async function signSolana(ctx, txs) {
67
+ const priv = hexToBytes(ctx.privateKey); // 32-byte ed25519 seed
68
+ const blockhash = await latestBlockhash();
69
+ const signed = [];
70
+ logInfo("sign.solana.start", {
71
+ address: ctx.address,
72
+ txCount: txs.length,
73
+ blockhash: bs58.encode(blockhash),
74
+ });
75
+ for (const item of txs) {
76
+ if (!item.txData)
77
+ throw new Error("Solana transactionToSign has no txData.");
78
+ const message = hexToBytes(item.txData);
79
+ const { offset, numSigners } = blockhashOffset(message);
80
+ if (numSigners !== 1) {
81
+ throw new Error(`Solana tx requires ${numSigners} signers; only single-signer transfers are supported.`);
82
+ }
83
+ message.set(blockhash, offset);
84
+ const sig = ed25519.sign(message, priv);
85
+ // Wire format: [compact-u16 numSignatures = 1][signature][message]
86
+ const tx = new Uint8Array(1 + 64 + message.length);
87
+ tx[0] = 1;
88
+ tx.set(sig, 1);
89
+ tx.set(message, 65);
90
+ const txID = bs58.encode(sig);
91
+ logInfo("sign.solana.tx", {
92
+ transactionId: item.transactionId,
93
+ txID,
94
+ numSigners,
95
+ signedLen: tx.length,
96
+ });
97
+ signed.push({
98
+ signature: Buffer.from(tx).toString("hex"),
99
+ txData: item.txData,
100
+ txID,
101
+ transactionId: item.transactionId,
102
+ });
103
+ }
104
+ return signed;
105
+ }
106
+ //# sourceMappingURL=solana.js.map
@@ -0,0 +1 @@
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C,CAAC;QACH,MAAM,CAAC,IAAI,CAAC;YACV,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;YAC1C,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,IAAI;YACJ,aAAa,EAAE,IAAI,CAAC,aAAa;SAClC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Sign SWP create `txsToSign` into execute `signedTransactions`.
3
+ * Reuses per-network transfer signers via `dispatchSign`; maps to SWP DTO fields
4
+ * ({ type, signedTx, txData, txHash, txId }).
5
+ *
6
+ * EVM: live nonce/chainId already in signEvm; txHash = keccak256(signed tx).
7
+ */
8
+ import { type NetworkId } from "../config.js";
9
+ import type { SwapSignedTxDto, SwapTxToSign } from "../api/swap.js";
10
+ export declare function signSwapTransactions(network: NetworkId, mnemonic: string, txs: SwapTxToSign[]): Promise<SwapSignedTxDto[]>;
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Sign SWP create `txsToSign` into execute `signedTransactions`.
3
+ * Reuses per-network transfer signers via `dispatchSign`; maps to SWP DTO fields
4
+ * ({ type, signedTx, txData, txHash, txId }).
5
+ *
6
+ * EVM: live nonce/chainId already in signEvm; txHash = keccak256(signed tx).
7
+ */
8
+ import { keccak256, Transaction } from "ethers";
9
+ import { canSwap, isEvmNetwork } from "../config.js";
10
+ import { deriveKey } from "../wallet/derive.js";
11
+ import { dispatchSign } from "./dispatch.js";
12
+ import { logError, logInfo } from "../log.js";
13
+ function toSignItems(txs) {
14
+ return txs
15
+ .filter((t) => t.txData)
16
+ .map((t) => ({
17
+ txId: t.txId,
18
+ txData: t.txData,
19
+ extraData: t.extraData,
20
+ type: t.type,
21
+ transactionId: t.txId,
22
+ }));
23
+ }
24
+ function evmTxHash(signedHex) {
25
+ try {
26
+ return Transaction.from(signedHex).hash ?? keccak256(signedHex);
27
+ }
28
+ catch {
29
+ return keccak256(signedHex);
30
+ }
31
+ }
32
+ /**
33
+ * Map signer output → SWP execute DTO. Must match mobile forwardToSwap:
34
+ * EVM / Tron / Bitcoin / Solana: signedTx=signature, txData=original unsigned
35
+ * TON: signedTx=txData=external message BoC hex
36
+ * XRP: signedTx=TxnSignature, txData=signed blob
37
+ */
38
+ function mapSigned(network, original, signed) {
39
+ const out = [];
40
+ let si = 0;
41
+ for (const orig of original) {
42
+ if (!orig.txData)
43
+ continue;
44
+ const s = signed[si++];
45
+ if (!s)
46
+ throw new Error("Signer returned fewer transactions than expected.");
47
+ const txId = orig.txId ?? s.txID ?? "";
48
+ const signedTx = s.signature;
49
+ let txData;
50
+ let txHash;
51
+ if (network === "ton") {
52
+ // Mobile: both fields are the signed external-message BoC.
53
+ txData = signedTx;
54
+ txHash = s.txID || txId;
55
+ }
56
+ else if (network === "xrp") {
57
+ txData = s.txData; // signed blob
58
+ txHash = s.txID || txId;
59
+ }
60
+ else if (isEvmNetwork(network)) {
61
+ txData = orig.txData;
62
+ txHash = evmTxHash(signedTx);
63
+ }
64
+ else {
65
+ // tron, bitcoin, solana — original unsigned txData
66
+ txData = orig.txData;
67
+ txHash = s.txID || txId;
68
+ }
69
+ out.push({
70
+ type: orig.type ?? "",
71
+ signedTx,
72
+ txData,
73
+ txHash,
74
+ txId,
75
+ });
76
+ }
77
+ return out;
78
+ }
79
+ export async function signSwapTransactions(network, mnemonic, txs) {
80
+ if (!canSwap(network)) {
81
+ throw new Error(`Swap signing is not supported on "${network}".`);
82
+ }
83
+ const started = Date.now();
84
+ const { privateKey, address } = deriveKey(mnemonic, network);
85
+ const ctx = { privateKey, address };
86
+ const items = toSignItems(txs);
87
+ logInfo("sign.swap.start", {
88
+ network,
89
+ address,
90
+ txCount: items.length,
91
+ types: items.map((t) => t.type),
92
+ });
93
+ try {
94
+ const signed = await dispatchSign(network, ctx, items);
95
+ const mapped = mapSigned(network, txs, signed);
96
+ logInfo("sign.swap.ok", {
97
+ network,
98
+ address,
99
+ elapsedMs: Date.now() - started,
100
+ signedCount: mapped.length,
101
+ });
102
+ return mapped;
103
+ }
104
+ catch (e) {
105
+ logError("sign.swap.fail", e, {
106
+ network,
107
+ address,
108
+ txCount: items.length,
109
+ elapsedMs: Date.now() - started,
110
+ });
111
+ throw e;
112
+ }
113
+ }
114
+ //# sourceMappingURL=swap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swap.js","sourceRoot":"","sources":["../../src/signing/swap.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAkB,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE9C,SAAS,WAAW,CAAC,GAAmB;IACtC,OAAO,GAAG;SACP,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;SACvB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACX,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,SAAS,EAAE,CAAC,CAAC,SAAS;QACtB,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,aAAa,EAAE,CAAC,CAAC,IAAI;KACtB,CAAC,CAAC,CAAC;AACR,CAAC;AAED,SAAS,SAAS,CAAC,SAAiB;IAClC,IAAI,CAAC;QACH,OAAO,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,IAAI,SAAS,CAAC,SAAS,CAAC,CAAC;IAClE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC,SAAS,CAAC,CAAC;IAC9B,CAAC;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,gBAAgB,EAAE,CAAC,EAAE;YAC5B,OAAO;YACP,OAAO;YACP,OAAO,EAAE,KAAK,CAAC,MAAM;YACrB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO;SAChC,CAAC,CAAC;QACH,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * TON signing — matches mobile `ton_net_api_client` (IR-673 RelayV2 path):
3
+ *
4
+ * Relay estimate returns unsigned wallet-transfer bodies as BoC in `txData`
5
+ * (hex or base64). The client ed25519-signs each cell hash, wraps the signed
6
+ * body in an external message (with wallet init when seqno == 0), and puts the
7
+ * external-message BoC hex into both `signature` and `txData` of the forward
8
+ * payload.
9
+ *
10
+ * Estimate must include `fromPublicKey` (32-byte ed25519 pubkey hex) — same as
11
+ * mobile `RelayV2EstimateRequest.fromPublicKey` for NetType.ton.
12
+ *
13
+ * `sendTon` remains as a direct TonCenter broadcast fallback (pre-relay path).
14
+ */
15
+ import type { SignContext, SignedTransaction, TransactionToSign } from "./types.js";
16
+ /** 32-byte ed25519 public key hex (no 0x), for relay estimate `fromPublicKey`. */
17
+ export declare function tonPublicKeyHex(mnemonic: string): string;
18
+ /**
19
+ * Sign relay `transactionsToSign` the same way as mobile
20
+ * `_signRelayWalletTransfer`: signature || unsigned body → external message BoC.
21
+ */
22
+ export declare function signTon(ctx: SignContext, txs: TransactionToSign[]): SignedTransaction[];
23
+ export interface TonSendParams {
24
+ to: string;
25
+ /** Amount in TON (decimal string). */
26
+ amount: string;
27
+ memo?: string;
28
+ }
29
+ export interface TonSendResult {
30
+ txHash: string;
31
+ }
32
+ /** Direct TonCenter broadcast (legacy / fallback; mobile still keeps this path). */
33
+ export declare function sendTon(mnemonic: string, params: TonSendParams): Promise<TonSendResult>;