verus-rpc 0.1.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 (75) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +139 -0
  3. package/dist/amount.d.ts +32 -0
  4. package/dist/amount.d.ts.map +1 -0
  5. package/dist/amount.js +65 -0
  6. package/dist/amount.js.map +1 -0
  7. package/dist/client.d.ts +60 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +61 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/errors.d.ts +81 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +107 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/index.d.ts +16 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +21 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/lossless.d.ts +32 -0
  20. package/dist/lossless.d.ts.map +1 -0
  21. package/dist/lossless.js +64 -0
  22. package/dist/lossless.js.map +1 -0
  23. package/dist/mapping.d.ts +41 -0
  24. package/dist/mapping.d.ts.map +1 -0
  25. package/dist/mapping.js +139 -0
  26. package/dist/mapping.js.map +1 -0
  27. package/dist/methods/addressindex.d.ts +69 -0
  28. package/dist/methods/addressindex.d.ts.map +1 -0
  29. package/dist/methods/addressindex.js +97 -0
  30. package/dist/methods/addressindex.js.map +1 -0
  31. package/dist/methods/blockchain.d.ts +99 -0
  32. package/dist/methods/blockchain.d.ts.map +1 -0
  33. package/dist/methods/blockchain.js +141 -0
  34. package/dist/methods/blockchain.js.map +1 -0
  35. package/dist/methods/chain.d.ts +39 -0
  36. package/dist/methods/chain.d.ts.map +1 -0
  37. package/dist/methods/chain.js +44 -0
  38. package/dist/methods/chain.js.map +1 -0
  39. package/dist/methods/currency.d.ts +210 -0
  40. package/dist/methods/currency.d.ts.map +1 -0
  41. package/dist/methods/currency.js +303 -0
  42. package/dist/methods/currency.js.map +1 -0
  43. package/dist/methods/identity.d.ts +284 -0
  44. package/dist/methods/identity.d.ts.map +1 -0
  45. package/dist/methods/identity.js +333 -0
  46. package/dist/methods/identity.js.map +1 -0
  47. package/dist/methods/shielded.d.ts +136 -0
  48. package/dist/methods/shielded.d.ts.map +1 -0
  49. package/dist/methods/shielded.js +175 -0
  50. package/dist/methods/shielded.js.map +1 -0
  51. package/dist/methods/t2.d.ts +8 -0
  52. package/dist/methods/t2.d.ts.map +1 -0
  53. package/dist/methods/t2.js +10 -0
  54. package/dist/methods/t2.js.map +1 -0
  55. package/dist/methods/wallet-types.d.ts +143 -0
  56. package/dist/methods/wallet-types.d.ts.map +1 -0
  57. package/dist/methods/wallet-types.js +6 -0
  58. package/dist/methods/wallet-types.js.map +1 -0
  59. package/dist/methods/wallet.d.ts +206 -0
  60. package/dist/methods/wallet.d.ts.map +1 -0
  61. package/dist/methods/wallet.js +455 -0
  62. package/dist/methods/wallet.js.map +1 -0
  63. package/dist/mock.d.ts +28 -0
  64. package/dist/mock.d.ts.map +1 -0
  65. package/dist/mock.js +61 -0
  66. package/dist/mock.js.map +1 -0
  67. package/dist/resilience.d.ts +20 -0
  68. package/dist/resilience.d.ts.map +1 -0
  69. package/dist/resilience.js +32 -0
  70. package/dist/resilience.js.map +1 -0
  71. package/dist/transport.d.ts +38 -0
  72. package/dist/transport.d.ts.map +1 -0
  73. package/dist/transport.js +79 -0
  74. package/dist/transport.js.map +1 -0
  75. package/package.json +59 -0
@@ -0,0 +1,206 @@
1
+ import type { RpcTransport } from "../transport.js";
2
+ import type { GetWalletInfoResult, GroupedAddress, ImportAddressOptions, ImportPrivKeyOptions, ListReceivedOptions, ListTransactionsOptions, ListUnspentOptions, ListedTransaction, ReceivedByAddressEntry, SendManyOptions, SignMessageOptions, SignMessageResult, UnspentOutput, VerifyMessageOptions } from "./wallet-types.js";
3
+ export interface GetBalanceOptions {
4
+ /** Only count transactions with at least this many confirmations. */
5
+ minConf?: number;
6
+ includeWatchOnly?: boolean;
7
+ }
8
+ export interface GetCurrencyBalanceOptions {
9
+ /** Transparent address, identity (`name@`), or wildcard. */
10
+ address: string;
11
+ minConf?: number;
12
+ /** Return currency names instead of i-addresses as keys. */
13
+ friendlyNames?: boolean;
14
+ includeShared?: boolean;
15
+ }
16
+ export interface GetTransactionOptions {
17
+ txid: string;
18
+ includeWatchOnly?: boolean;
19
+ }
20
+ export interface TransactionDetail {
21
+ address?: string | undefined;
22
+ /** "send" | "receive" | "generate" | "immature" | "orphan" */
23
+ category: string;
24
+ /** Signed value — negative for sends. Bigint sats. */
25
+ amount: bigint;
26
+ vout?: number | undefined;
27
+ /** Signed value — negative. Bigint sats. */
28
+ fee?: bigint | undefined;
29
+ size?: number | undefined;
30
+ [key: string]: unknown;
31
+ }
32
+ export interface GetTransactionResult {
33
+ /** Signed net wallet effect — bigint sats. */
34
+ amount: bigint;
35
+ /** Signed fee (negative) — bigint sats. Present for sends. */
36
+ fee?: bigint | undefined;
37
+ confirmations: number;
38
+ blockhash?: string | undefined;
39
+ blockindex?: number | undefined;
40
+ blocktime?: number | undefined;
41
+ expiryheight?: number | undefined;
42
+ txid: string;
43
+ time: number;
44
+ timereceived: number;
45
+ details: TransactionDetail[];
46
+ hex?: string | undefined;
47
+ [key: string]: unknown;
48
+ }
49
+ export interface SendCurrencyOutput {
50
+ /** Destination: transparent/z address or identity (`name@`). */
51
+ address: string;
52
+ /** Bigint sats — serialized as an exact JSON number for the daemon. */
53
+ amount: bigint;
54
+ /** Source currency; defaults to the chain's native currency. */
55
+ currency?: string | undefined;
56
+ /** Convert to this currency on the way (typed first-class in Etappe 4). */
57
+ convertto?: string | undefined;
58
+ /** Conversion routing via this (fractional) currency. */
59
+ via?: string | undefined;
60
+ exportto?: string | undefined;
61
+ feecurrency?: string | undefined;
62
+ /** Hex or text memo (z-address outputs only). */
63
+ memo?: string | undefined;
64
+ refundto?: string | undefined;
65
+ preconvert?: boolean | undefined;
66
+ burn?: boolean | undefined;
67
+ mintnew?: boolean | undefined;
68
+ }
69
+ export interface SendCurrencyOptions {
70
+ /** Source address, identity, or `"*"` for any wallet funds. */
71
+ fromAddress: string;
72
+ outputs: SendCurrencyOutput[];
73
+ minConf?: number;
74
+ /** Explicit fee — bigint sats. */
75
+ feeAmount?: bigint;
76
+ }
77
+ export interface OperationError {
78
+ code: number;
79
+ message: string;
80
+ [key: string]: unknown;
81
+ }
82
+ export interface OperationResult {
83
+ txid?: string | undefined;
84
+ [key: string]: unknown;
85
+ }
86
+ /** One entry of `z_getoperationstatus` — async wallet operation state. */
87
+ export interface OperationStatus {
88
+ id: string;
89
+ /** "queued" | "executing" | "success" | "failed" | "cancelled" */
90
+ status: string;
91
+ creation_time?: number | undefined;
92
+ method?: string | undefined;
93
+ /** Original call params, safe-number converted (amounts arrive as exact decimal strings). */
94
+ params?: unknown;
95
+ result?: OperationResult | undefined;
96
+ error?: OperationError | undefined;
97
+ [key: string]: unknown;
98
+ }
99
+ export interface GetOperationStatusOptions {
100
+ /** Restrict to these opids; all known operations when omitted. */
101
+ operationIds?: string[];
102
+ }
103
+ export interface SendCurrencyAndWaitOptions extends SendCurrencyOptions {
104
+ /** Poll interval for z_getoperationstatus. Default 1s. */
105
+ pollIntervalMs?: number;
106
+ /** Deadline for the operation to reach a final state. Default 120s. */
107
+ waitTimeoutMs?: number;
108
+ }
109
+ export interface SendCurrencyAndWaitResult {
110
+ opid: string;
111
+ txid: string;
112
+ }
113
+ export declare function mapGetTransaction(raw: unknown): GetTransactionResult;
114
+ export declare function mapCurrencyBalance(raw: unknown): Record<string, bigint>;
115
+ export declare function mapOperationStatus(raw: unknown, index: number): OperationStatus;
116
+ export declare function mapUnspentOutput(raw: unknown, index: number): UnspentOutput;
117
+ export declare function mapListedTransaction(raw: unknown, index: number): ListedTransaction;
118
+ export declare function mapGetWalletInfo(raw: unknown): GetWalletInfoResult;
119
+ export declare function mapAddressGroupings(raw: unknown): GroupedAddress[][];
120
+ export declare function mapSignMessage(raw: unknown): SignMessageResult;
121
+ /** Wallet family — balances, transactions, sends, async operations. */
122
+ export declare class WalletApi {
123
+ private readonly transport;
124
+ constructor(transport: RpcTransport);
125
+ /** Confirmed native-currency wallet balance — bigint sats. */
126
+ getBalance(options?: GetBalanceOptions): Promise<bigint>;
127
+ /** Per-currency balances of one address/identity — bigint sats per currency. */
128
+ getCurrencyBalance(options: GetCurrencyBalanceOptions): Promise<Record<string, bigint>>;
129
+ /** Detailed wallet view of one transaction. */
130
+ getTransaction(options: GetTransactionOptions): Promise<GetTransactionResult>;
131
+ /**
132
+ * Send currency (async daemon operation). Returns the operation id —
133
+ * use `getOperationStatus` or `sendCurrencyAndWait` for the txid.
134
+ */
135
+ sendCurrency(options: SendCurrencyOptions): Promise<string>;
136
+ /** `z_getoperationstatus` — state of async wallet operations. */
137
+ getOperationStatus(options?: GetOperationStatusOptions): Promise<OperationStatus[]>;
138
+ /**
139
+ * `sendcurrency` + poll `z_getoperationstatus` until the operation reaches
140
+ * a final state. Resolves with the txid on success; throws
141
+ * `OperationFailedError` / `OperationTimeoutError` otherwise.
142
+ */
143
+ sendCurrencyAndWait(options: SendCurrencyAndWaitOptions): Promise<SendCurrencyAndWaitResult>;
144
+ /** Unspent transparent outputs — amounts as bigint sats. */
145
+ listUnspent(options?: ListUnspentOptions): Promise<UnspentOutput[]>;
146
+ /** Most recent wallet transactions — amounts as bigint sats. */
147
+ listTransactions(options?: ListTransactionsOptions): Promise<ListedTransaction[]>;
148
+ /** Send to multiple transparent recipients in one transaction. Returns the txid. */
149
+ sendMany(options: SendManyOptions): Promise<string>;
150
+ /** New transparent receiving address. */
151
+ getNewAddress(): Promise<string>;
152
+ /** New transparent change address. */
153
+ getRawChangeAddress(): Promise<string>;
154
+ /** Wallet state — balances as bigint sats. */
155
+ getWalletInfo(): Promise<GetWalletInfoResult>;
156
+ /** Unconfirmed native-currency balance — bigint sats. */
157
+ getUnconfirmedBalance(): Promise<bigint>;
158
+ /** Address clusters with common ownership — amounts as bigint sats. */
159
+ listAddressGroupings(): Promise<GroupedAddress[][]>;
160
+ /** Sign a message with an address key or identity. */
161
+ signMessage(options: SignMessageOptions): Promise<SignMessageResult>;
162
+ /**
163
+ * Verify a message signature. For identity signers, set
164
+ * `checkLatest: true` unless you specifically need historical validity —
165
+ * see `VerifyMessageOptions`.
166
+ */
167
+ verifyMessage(options: VerifyMessageOptions): Promise<boolean>;
168
+ /** T2 helper: request + safe-number conversion + typed cast. */
169
+ private t2;
170
+ /** Received totals per address. T2 — amounts as exact decimal strings. */
171
+ listReceivedByAddress(options?: ListReceivedOptions): Promise<ReceivedByAddressEntry[]>;
172
+ /** Total received by one address. T2 — exact decimal string. */
173
+ getReceivedByAddress(options: {
174
+ address: string;
175
+ minConf?: number;
176
+ }): Promise<string>;
177
+ /**
178
+ * LEGACY (accounts era, deprecated upstream): balances per account label.
179
+ * T2 — amounts as exact decimal strings. Prefer identities/addresses.
180
+ */
181
+ listAccounts(options?: {
182
+ minConf?: number;
183
+ includeWatchOnly?: boolean;
184
+ }): Promise<Record<string, string>>;
185
+ /** Import a WIF private key into the wallet. Slow when rescanning. */
186
+ importPrivKey(options: ImportPrivKeyOptions): Promise<void>;
187
+ /** Watch an address or script without its key. */
188
+ importAddress(options: ImportAddressOptions): Promise<void>;
189
+ /** Import keys from a `dumpwallet` file (server-side path). */
190
+ importWallet(options: {
191
+ filename: string;
192
+ }): Promise<void>;
193
+ /** SECRET: WIF private key for an address. Do not log the result. */
194
+ dumpPrivKey(options: {
195
+ address: string;
196
+ }): Promise<string>;
197
+ /** Dump all wallet keys to a server-side file. Returns the full path. */
198
+ dumpWallet(options: {
199
+ filename: string;
200
+ }): Promise<string>;
201
+ /** Copy wallet.dat to a server-side destination. Returns the full path. */
202
+ backupWallet(options: {
203
+ destination: string;
204
+ }): Promise<string>;
205
+ }
206
+ //# sourceMappingURL=wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/methods/wallet.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE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CAAC;IAOjE,kDAAkD;IAC5C,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjE,+DAA+D;IACzD,YAAY,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhE,qEAAqE;IAC/D,WAAW,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAOhE,yEAAyE;IACnE,UAAU,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAQhE,2EAA2E;IACrE,YAAY,CAAC,OAAO,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CAMtE"}
@@ -0,0 +1,455 @@
1
+ import { formatAmount } from "../amount.js";
2
+ import { OperationFailedError, OperationTimeoutError, ResponseMappingError } from "../errors.js";
3
+ import { LosslessNumber, toSafeNumbers } from "../lossless.js";
4
+ import { expectArray, expectObject, mapAmount, mapAmountOptional, mapBoolean, mapBooleanOptional, mapInt, mapIntOptional, mapString, mapStringOptional, withPassthrough, } from "../mapping.js";
5
+ export function mapGetTransaction(raw) {
6
+ const method = "gettransaction";
7
+ const obj = expectObject(raw, method);
8
+ const ctx = (field) => ({ method, field });
9
+ const details = expectArray(obj["details"] ?? [], method, "details").map((item, i) => {
10
+ const d = expectObject(item, method);
11
+ const dctx = (field) => ({ method, field: `details[${i}].${field}` });
12
+ return withPassthrough(d, {
13
+ address: mapStringOptional(d["address"], dctx("address")),
14
+ category: mapString(d["category"], dctx("category")),
15
+ amount: mapAmount(d["amount"], dctx("amount"), { signed: true }),
16
+ vout: mapIntOptional(d["vout"], dctx("vout")),
17
+ fee: mapAmountOptional(d["fee"], dctx("fee"), { signed: true }),
18
+ size: mapIntOptional(d["size"], dctx("size")),
19
+ });
20
+ });
21
+ return withPassthrough(obj, {
22
+ amount: mapAmount(obj["amount"], ctx("amount"), { signed: true }),
23
+ fee: mapAmountOptional(obj["fee"], ctx("fee"), { signed: true }),
24
+ confirmations: mapInt(obj["confirmations"], ctx("confirmations")),
25
+ blockhash: mapStringOptional(obj["blockhash"], ctx("blockhash")),
26
+ blockindex: mapIntOptional(obj["blockindex"], ctx("blockindex")),
27
+ blocktime: mapIntOptional(obj["blocktime"], ctx("blocktime")),
28
+ expiryheight: mapIntOptional(obj["expiryheight"], ctx("expiryheight")),
29
+ txid: mapString(obj["txid"], ctx("txid")),
30
+ time: mapInt(obj["time"], ctx("time")),
31
+ timereceived: mapInt(obj["timereceived"], ctx("timereceived")),
32
+ details,
33
+ hex: mapStringOptional(obj["hex"], ctx("hex")),
34
+ });
35
+ }
36
+ export function mapCurrencyBalance(raw) {
37
+ const method = "getcurrencybalance";
38
+ const obj = expectObject(raw, method);
39
+ const balances = {};
40
+ for (const [currency, value] of Object.entries(obj)) {
41
+ balances[currency] = mapAmount(value, { method, field: currency });
42
+ }
43
+ return balances;
44
+ }
45
+ export function mapOperationStatus(raw, index) {
46
+ const method = "z_getoperationstatus";
47
+ const obj = expectObject(raw, method);
48
+ const ctx = (field) => ({ method, field: `[${index}].${field}` });
49
+ const rawResult = obj["result"];
50
+ const rawError = obj["error"];
51
+ return withPassthrough(obj, {
52
+ id: mapString(obj["id"], ctx("id")),
53
+ status: mapString(obj["status"], ctx("status")),
54
+ creation_time: mapIntOptional(obj["creation_time"], ctx("creation_time")),
55
+ method: mapStringOptional(obj["method"], ctx("method")),
56
+ params: obj["params"] === undefined ? undefined : toSafeNumbers(obj["params"]),
57
+ result: rawResult === undefined || rawResult === null
58
+ ? undefined
59
+ : toSafeNumbers(expectObject(rawResult, method)),
60
+ error: rawError === undefined || rawError === null
61
+ ? undefined
62
+ : mapOperationError(expectObject(rawError, method), ctx("error")),
63
+ });
64
+ }
65
+ function mapOperationError(obj, ctx) {
66
+ return withPassthrough(obj, {
67
+ code: mapInt(obj["code"], { method: ctx.method, field: `${ctx.field}.code` }),
68
+ message: mapString(obj["message"], { method: ctx.method, field: `${ctx.field}.message` }),
69
+ });
70
+ }
71
+ export function mapUnspentOutput(raw, index) {
72
+ const method = "listunspent";
73
+ const obj = expectObject(raw, method);
74
+ const ctx = (field) => ({ method, field: `[${index}].${field}` });
75
+ return withPassthrough(obj, {
76
+ txid: mapString(obj["txid"], ctx("txid")),
77
+ vout: mapInt(obj["vout"], ctx("vout")),
78
+ address: mapStringOptional(obj["address"], ctx("address")),
79
+ scriptPubKey: mapStringOptional(obj["scriptPubKey"], ctx("scriptPubKey")),
80
+ amount: mapAmount(obj["amount"], ctx("amount")),
81
+ confirmations: mapInt(obj["confirmations"], ctx("confirmations")),
82
+ generated: mapBooleanOptional(obj["generated"], ctx("generated")),
83
+ spendable: mapBooleanOptional(obj["spendable"], ctx("spendable")),
84
+ redeemScript: mapStringOptional(obj["redeemScript"], ctx("redeemScript")),
85
+ });
86
+ }
87
+ export function mapListedTransaction(raw, index) {
88
+ const method = "listtransactions";
89
+ const obj = expectObject(raw, method);
90
+ const ctx = (field) => ({ method, field: `[${index}].${field}` });
91
+ return withPassthrough(obj, {
92
+ address: mapStringOptional(obj["address"], ctx("address")),
93
+ category: mapString(obj["category"], ctx("category")),
94
+ amount: mapAmount(obj["amount"], ctx("amount"), { signed: true }),
95
+ vout: mapIntOptional(obj["vout"], ctx("vout")),
96
+ fee: mapAmountOptional(obj["fee"], ctx("fee"), { signed: true }),
97
+ confirmations: mapIntOptional(obj["confirmations"], ctx("confirmations")),
98
+ blockhash: mapStringOptional(obj["blockhash"], ctx("blockhash")),
99
+ blockindex: mapIntOptional(obj["blockindex"], ctx("blockindex")),
100
+ blocktime: mapIntOptional(obj["blocktime"], ctx("blocktime")),
101
+ txid: mapStringOptional(obj["txid"], ctx("txid")),
102
+ time: mapInt(obj["time"], ctx("time")),
103
+ timereceived: mapIntOptional(obj["timereceived"], ctx("timereceived")),
104
+ comment: mapStringOptional(obj["comment"], ctx("comment")),
105
+ size: mapIntOptional(obj["size"], ctx("size")),
106
+ });
107
+ }
108
+ export function mapGetWalletInfo(raw) {
109
+ const method = "getwalletinfo";
110
+ const obj = expectObject(raw, method);
111
+ const ctx = (field) => ({ method, field });
112
+ return withPassthrough(obj, {
113
+ walletversion: mapInt(obj["walletversion"], ctx("walletversion")),
114
+ balance: mapAmount(obj["balance"], ctx("balance")),
115
+ unconfirmed_balance: mapAmount(obj["unconfirmed_balance"], ctx("unconfirmed_balance")),
116
+ immature_balance: mapAmount(obj["immature_balance"], ctx("immature_balance")),
117
+ txcount: mapInt(obj["txcount"], ctx("txcount")),
118
+ keypoololdest: mapIntOptional(obj["keypoololdest"], ctx("keypoololdest")),
119
+ keypoolsize: mapIntOptional(obj["keypoolsize"], ctx("keypoolsize")),
120
+ unlocked_until: mapIntOptional(obj["unlocked_until"], ctx("unlocked_until")),
121
+ paytxfee: mapAmountOptional(obj["paytxfee"], ctx("paytxfee")),
122
+ seedfp: mapStringOptional(obj["seedfp"], ctx("seedfp")),
123
+ });
124
+ }
125
+ export function mapAddressGroupings(raw) {
126
+ const method = "listaddressgroupings";
127
+ return expectArray(raw, method).map((group, g) => expectArray(group, method, `[${g}]`).map((entry, e) => {
128
+ const tuple = expectArray(entry, method, `[${g}][${e}]`);
129
+ const address = mapString(tuple[0], { method, field: `[${g}][${e}][0]` });
130
+ const amount = mapAmount(tuple[1], { method, field: `[${g}][${e}][1]` });
131
+ const account = mapStringOptional(tuple[2], { method, field: `[${g}][${e}][2]` });
132
+ return account === undefined ? { address, amount } : { address, amount, account };
133
+ }));
134
+ }
135
+ export function mapSignMessage(raw) {
136
+ const method = "signmessage";
137
+ const obj = expectObject(raw, method);
138
+ return withPassthrough(obj, {
139
+ hash: mapString(obj["hash"], { method, field: "hash" }),
140
+ signature: mapString(obj["signature"], { method, field: "signature" }),
141
+ });
142
+ }
143
+ function serializeOutput(output) {
144
+ const raw = {
145
+ address: output.address,
146
+ amount: new LosslessNumber(formatAmount(output.amount)),
147
+ };
148
+ if (output.currency !== undefined)
149
+ raw["currency"] = output.currency;
150
+ if (output.convertto !== undefined)
151
+ raw["convertto"] = output.convertto;
152
+ if (output.via !== undefined)
153
+ raw["via"] = output.via;
154
+ if (output.exportto !== undefined)
155
+ raw["exportto"] = output.exportto;
156
+ if (output.feecurrency !== undefined)
157
+ raw["feecurrency"] = output.feecurrency;
158
+ if (output.memo !== undefined)
159
+ raw["memo"] = output.memo;
160
+ if (output.refundto !== undefined)
161
+ raw["refundto"] = output.refundto;
162
+ if (output.preconvert !== undefined)
163
+ raw["preconvert"] = output.preconvert;
164
+ if (output.burn !== undefined)
165
+ raw["burn"] = output.burn;
166
+ if (output.mintnew !== undefined)
167
+ raw["mintnew"] = output.mintnew;
168
+ return raw;
169
+ }
170
+ function sleep(ms) {
171
+ return new Promise((resolve) => setTimeout(resolve, ms));
172
+ }
173
+ /** Wallet family — balances, transactions, sends, async operations. */
174
+ export class WalletApi {
175
+ transport;
176
+ constructor(transport) {
177
+ this.transport = transport;
178
+ }
179
+ /** Confirmed native-currency wallet balance — bigint sats. */
180
+ async getBalance(options) {
181
+ const params = [];
182
+ if (options?.minConf !== undefined || options?.includeWatchOnly !== undefined) {
183
+ // Positional daemon params: the deprecated account slot must be "*".
184
+ params.push("*", options.minConf ?? 1);
185
+ if (options.includeWatchOnly !== undefined)
186
+ params.push(options.includeWatchOnly);
187
+ }
188
+ return mapAmount(await this.transport.request("getbalance", params), {
189
+ method: "getbalance",
190
+ field: "(result)",
191
+ });
192
+ }
193
+ /** Per-currency balances of one address/identity — bigint sats per currency. */
194
+ async getCurrencyBalance(options) {
195
+ const params = [options.address];
196
+ const needFriendly = options.friendlyNames !== undefined || options.includeShared !== undefined;
197
+ if (options.minConf !== undefined || needFriendly)
198
+ params.push(options.minConf ?? 1);
199
+ if (needFriendly)
200
+ params.push(options.friendlyNames ?? false);
201
+ if (options.includeShared !== undefined)
202
+ params.push(options.includeShared);
203
+ return mapCurrencyBalance(await this.transport.request("getcurrencybalance", params));
204
+ }
205
+ /** Detailed wallet view of one transaction. */
206
+ async getTransaction(options) {
207
+ const params = [options.txid];
208
+ if (options.includeWatchOnly !== undefined)
209
+ params.push(options.includeWatchOnly);
210
+ return mapGetTransaction(await this.transport.request("gettransaction", params));
211
+ }
212
+ /**
213
+ * Send currency (async daemon operation). Returns the operation id —
214
+ * use `getOperationStatus` or `sendCurrencyAndWait` for the txid.
215
+ */
216
+ async sendCurrency(options) {
217
+ const params = [options.fromAddress, options.outputs.map(serializeOutput)];
218
+ if (options.minConf !== undefined || options.feeAmount !== undefined) {
219
+ params.push(options.minConf ?? 1);
220
+ }
221
+ if (options.feeAmount !== undefined) {
222
+ params.push(new LosslessNumber(formatAmount(options.feeAmount)));
223
+ }
224
+ const result = await this.transport.request("sendcurrency", params);
225
+ return mapString(result, { method: "sendcurrency", field: "(result)" });
226
+ }
227
+ /** `z_getoperationstatus` — state of async wallet operations. */
228
+ async getOperationStatus(options) {
229
+ const params = options?.operationIds === undefined ? [] : [options.operationIds];
230
+ const result = expectArray(await this.transport.request("z_getoperationstatus", params), "z_getoperationstatus");
231
+ return result.map((item, i) => mapOperationStatus(item, i));
232
+ }
233
+ /**
234
+ * `sendcurrency` + poll `z_getoperationstatus` until the operation reaches
235
+ * a final state. Resolves with the txid on success; throws
236
+ * `OperationFailedError` / `OperationTimeoutError` otherwise.
237
+ */
238
+ async sendCurrencyAndWait(options) {
239
+ const { pollIntervalMs, waitTimeoutMs, ...sendOptions } = options;
240
+ const interval = pollIntervalMs ?? 1_000;
241
+ const timeout = waitTimeoutMs ?? 120_000;
242
+ const opid = await this.sendCurrency(sendOptions);
243
+ const deadline = Date.now() + timeout;
244
+ for (;;) {
245
+ const statuses = await this.getOperationStatus({ operationIds: [opid] });
246
+ const status = statuses.find((s) => s.id === opid);
247
+ if (status !== undefined) {
248
+ if (status.status === "success") {
249
+ const txid = status.result?.txid;
250
+ if (typeof txid !== "string") {
251
+ throw new ResponseMappingError("z_getoperationstatus", "result.txid", "success without txid");
252
+ }
253
+ return { opid, txid };
254
+ }
255
+ if (status.status === "failed" || status.status === "cancelled") {
256
+ throw new OperationFailedError(opid, status.status, status.error?.code, status.error?.message ?? "no error message");
257
+ }
258
+ }
259
+ const remaining = deadline - Date.now();
260
+ if (remaining <= 0) {
261
+ throw new OperationTimeoutError(opid, timeout);
262
+ }
263
+ await sleep(Math.min(interval, remaining));
264
+ }
265
+ }
266
+ // -------------------------------------------------------------------------
267
+ // T1 — wallet family (Etappe 2)
268
+ /** Unspent transparent outputs — amounts as bigint sats. */
269
+ async listUnspent(options) {
270
+ const params = [];
271
+ const needMax = options?.maxConf !== undefined || options?.addresses !== undefined;
272
+ if (options?.minConf !== undefined || needMax)
273
+ params.push(options.minConf ?? 1);
274
+ if (needMax)
275
+ params.push(options.maxConf ?? 9_999_999);
276
+ if (options?.addresses !== undefined)
277
+ params.push(options.addresses);
278
+ const result = expectArray(await this.transport.request("listunspent", params), "listunspent");
279
+ return result.map((item, i) => mapUnspentOutput(item, i));
280
+ }
281
+ /** Most recent wallet transactions — amounts as bigint sats. */
282
+ async listTransactions(options) {
283
+ const params = [];
284
+ const needFrom = options?.from !== undefined || options?.includeWatchOnly !== undefined;
285
+ if (options?.count !== undefined || needFrom) {
286
+ // Positional daemon params: the deprecated account slot must be "*".
287
+ params.push("*", options.count ?? 10);
288
+ }
289
+ if (needFrom)
290
+ params.push(options.from ?? 0);
291
+ if (options?.includeWatchOnly !== undefined)
292
+ params.push(options.includeWatchOnly);
293
+ const result = expectArray(await this.transport.request("listtransactions", params), "listtransactions");
294
+ return result.map((item, i) => mapListedTransaction(item, i));
295
+ }
296
+ /** Send to multiple transparent recipients in one transaction. Returns the txid. */
297
+ async sendMany(options) {
298
+ const amounts = {};
299
+ for (const [address, sats] of Object.entries(options.amounts)) {
300
+ amounts[address] = new LosslessNumber(formatAmount(sats));
301
+ }
302
+ // Positional: the deprecated account slot must be "".
303
+ const params = ["", amounts];
304
+ const needComment = options.comment !== undefined || options.subtractFeeFrom !== undefined;
305
+ if (options.minConf !== undefined || needComment)
306
+ params.push(options.minConf ?? 1);
307
+ if (needComment)
308
+ params.push(options.comment ?? "");
309
+ if (options.subtractFeeFrom !== undefined)
310
+ params.push(options.subtractFeeFrom);
311
+ return mapString(await this.transport.request("sendmany", params), { method: "sendmany", field: "(result)" });
312
+ }
313
+ /** New transparent receiving address. */
314
+ async getNewAddress() {
315
+ return mapString(await this.transport.request("getnewaddress", []), {
316
+ method: "getnewaddress",
317
+ field: "(result)",
318
+ });
319
+ }
320
+ /** New transparent change address. */
321
+ async getRawChangeAddress() {
322
+ return mapString(await this.transport.request("getrawchangeaddress", []), {
323
+ method: "getrawchangeaddress",
324
+ field: "(result)",
325
+ });
326
+ }
327
+ /** Wallet state — balances as bigint sats. */
328
+ async getWalletInfo() {
329
+ return mapGetWalletInfo(await this.transport.request("getwalletinfo", []));
330
+ }
331
+ /** Unconfirmed native-currency balance — bigint sats. */
332
+ async getUnconfirmedBalance() {
333
+ return mapAmount(await this.transport.request("getunconfirmedbalance", []), {
334
+ method: "getunconfirmedbalance",
335
+ field: "(result)",
336
+ });
337
+ }
338
+ /** Address clusters with common ownership — amounts as bigint sats. */
339
+ async listAddressGroupings() {
340
+ return mapAddressGroupings(await this.transport.request("listaddressgroupings", []));
341
+ }
342
+ /** Sign a message with an address key or identity. */
343
+ async signMessage(options) {
344
+ const params = [options.signer, options.message];
345
+ if (options.currentSignature !== undefined)
346
+ params.push(options.currentSignature);
347
+ return mapSignMessage(await this.transport.request("signmessage", params));
348
+ }
349
+ /**
350
+ * Verify a message signature. For identity signers, set
351
+ * `checkLatest: true` unless you specifically need historical validity —
352
+ * see `VerifyMessageOptions`.
353
+ */
354
+ async verifyMessage(options) {
355
+ const params = [options.signer, options.signature, options.message];
356
+ if (options.checkLatest !== undefined)
357
+ params.push(options.checkLatest);
358
+ return mapBoolean(await this.transport.request("verifymessage", params), {
359
+ method: "verifymessage",
360
+ field: "(result)",
361
+ });
362
+ }
363
+ // -------------------------------------------------------------------------
364
+ // T2 — typed (value fields as exact decimal strings)
365
+ /** T2 helper: request + safe-number conversion + typed cast. */
366
+ async t2(method, params) {
367
+ return toSafeNumbers(await this.transport.request(method, params));
368
+ }
369
+ /** Received totals per address. T2 — amounts as exact decimal strings. */
370
+ async listReceivedByAddress(options) {
371
+ const params = [];
372
+ const needEmpty = options?.includeEmpty !== undefined || options?.includeWatchOnly !== undefined;
373
+ if (options?.minConf !== undefined || needEmpty)
374
+ params.push(options.minConf ?? 1);
375
+ if (needEmpty)
376
+ params.push(options.includeEmpty ?? false);
377
+ if (options?.includeWatchOnly !== undefined)
378
+ params.push(options.includeWatchOnly);
379
+ return this.t2("listreceivedbyaddress", params);
380
+ }
381
+ /** Total received by one address. T2 — exact decimal string. */
382
+ async getReceivedByAddress(options) {
383
+ const params = [options.address];
384
+ if (options.minConf !== undefined)
385
+ params.push(options.minConf);
386
+ const result = await this.t2("getreceivedbyaddress", params);
387
+ return typeof result === "number" ? String(result) : result;
388
+ }
389
+ /**
390
+ * LEGACY (accounts era, deprecated upstream): balances per account label.
391
+ * T2 — amounts as exact decimal strings. Prefer identities/addresses.
392
+ */
393
+ async listAccounts(options) {
394
+ const params = [];
395
+ if (options?.minConf !== undefined || options?.includeWatchOnly !== undefined) {
396
+ params.push(options.minConf ?? 1);
397
+ }
398
+ if (options?.includeWatchOnly !== undefined)
399
+ params.push(options.includeWatchOnly);
400
+ const raw = await this.t2("listaccounts", params);
401
+ const out = {};
402
+ for (const [account, amount] of Object.entries(raw))
403
+ out[account] = String(amount);
404
+ return out;
405
+ }
406
+ // -------------------------------------------------------------------------
407
+ // T2 — key material & backups. NEVER logged, never fixture-recorded with
408
+ // real key material (mock-only tests). Handle results as secrets.
409
+ /** Import a WIF private key into the wallet. Slow when rescanning. */
410
+ async importPrivKey(options) {
411
+ const params = [options.privateKey];
412
+ if (options.label !== undefined || options.rescan !== undefined)
413
+ params.push(options.label ?? "");
414
+ if (options.rescan !== undefined)
415
+ params.push(options.rescan);
416
+ await this.transport.request("importprivkey", params);
417
+ }
418
+ /** Watch an address or script without its key. */
419
+ async importAddress(options) {
420
+ const params = [options.address];
421
+ if (options.label !== undefined || options.rescan !== undefined)
422
+ params.push(options.label ?? "");
423
+ if (options.rescan !== undefined)
424
+ params.push(options.rescan);
425
+ await this.transport.request("importaddress", params);
426
+ }
427
+ /** Import keys from a `dumpwallet` file (server-side path). */
428
+ async importWallet(options) {
429
+ await this.transport.request("importwallet", [options.filename]);
430
+ }
431
+ /** SECRET: WIF private key for an address. Do not log the result. */
432
+ async dumpPrivKey(options) {
433
+ return mapString(await this.transport.request("dumpprivkey", [options.address]), {
434
+ method: "dumpprivkey",
435
+ field: "(result)",
436
+ });
437
+ }
438
+ /** Dump all wallet keys to a server-side file. Returns the full path. */
439
+ async dumpWallet(options) {
440
+ const result = await this.transport.request("dumpwallet", [options.filename]);
441
+ // Older daemons return the path as a plain string, newer as {filename}.
442
+ if (typeof result === "string")
443
+ return result;
444
+ const obj = expectObject(result, "dumpwallet");
445
+ return mapString(obj["filename"], { method: "dumpwallet", field: "filename" });
446
+ }
447
+ /** Copy wallet.dat to a server-side destination. Returns the full path. */
448
+ async backupWallet(options) {
449
+ return mapString(await this.transport.request("backupwallet", [options.destination]), {
450
+ method: "backupwallet",
451
+ field: "(result)",
452
+ });
453
+ }
454
+ }
455
+ //# sourceMappingURL=wallet.js.map