xpi-ts 0.2.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 (216) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +516 -0
  3. package/dist/index.d.ts +9 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +8 -0
  6. package/dist/lib/bitcore/address.d.ts +66 -0
  7. package/dist/lib/bitcore/address.d.ts.map +1 -0
  8. package/dist/lib/bitcore/address.js +407 -0
  9. package/dist/lib/bitcore/block/block.d.ts +57 -0
  10. package/dist/lib/bitcore/block/block.d.ts.map +1 -0
  11. package/dist/lib/bitcore/block/block.js +233 -0
  12. package/dist/lib/bitcore/block/blockheader.d.ts +82 -0
  13. package/dist/lib/bitcore/block/blockheader.d.ts.map +1 -0
  14. package/dist/lib/bitcore/block/blockheader.js +323 -0
  15. package/dist/lib/bitcore/block/index.d.ts +5 -0
  16. package/dist/lib/bitcore/block/index.d.ts.map +1 -0
  17. package/dist/lib/bitcore/block/index.js +2 -0
  18. package/dist/lib/bitcore/chunk.d.ts +22 -0
  19. package/dist/lib/bitcore/chunk.d.ts.map +1 -0
  20. package/dist/lib/bitcore/chunk.js +46 -0
  21. package/dist/lib/bitcore/crypto/bn.d.ts +53 -0
  22. package/dist/lib/bitcore/crypto/bn.d.ts.map +1 -0
  23. package/dist/lib/bitcore/crypto/bn.js +238 -0
  24. package/dist/lib/bitcore/crypto/ecdsa.d.ts +46 -0
  25. package/dist/lib/bitcore/crypto/ecdsa.d.ts.map +1 -0
  26. package/dist/lib/bitcore/crypto/ecdsa.js +247 -0
  27. package/dist/lib/bitcore/crypto/hash.d.ts +16 -0
  28. package/dist/lib/bitcore/crypto/hash.d.ts.map +1 -0
  29. package/dist/lib/bitcore/crypto/hash.js +87 -0
  30. package/dist/lib/bitcore/crypto/index.d.ts +9 -0
  31. package/dist/lib/bitcore/crypto/index.d.ts.map +1 -0
  32. package/dist/lib/bitcore/crypto/index.js +8 -0
  33. package/dist/lib/bitcore/crypto/musig2.d.ts +40 -0
  34. package/dist/lib/bitcore/crypto/musig2.d.ts.map +1 -0
  35. package/dist/lib/bitcore/crypto/musig2.js +236 -0
  36. package/dist/lib/bitcore/crypto/point.d.ts +20 -0
  37. package/dist/lib/bitcore/crypto/point.d.ts.map +1 -0
  38. package/dist/lib/bitcore/crypto/point.js +133 -0
  39. package/dist/lib/bitcore/crypto/random.d.ts +7 -0
  40. package/dist/lib/bitcore/crypto/random.d.ts.map +1 -0
  41. package/dist/lib/bitcore/crypto/random.js +30 -0
  42. package/dist/lib/bitcore/crypto/schnorr.d.ts +40 -0
  43. package/dist/lib/bitcore/crypto/schnorr.d.ts.map +1 -0
  44. package/dist/lib/bitcore/crypto/schnorr.js +185 -0
  45. package/dist/lib/bitcore/crypto/signature.d.ts +53 -0
  46. package/dist/lib/bitcore/crypto/signature.d.ts.map +1 -0
  47. package/dist/lib/bitcore/crypto/signature.js +300 -0
  48. package/dist/lib/bitcore/crypto/sigtype.d.ts +5 -0
  49. package/dist/lib/bitcore/crypto/sigtype.d.ts.map +1 -0
  50. package/dist/lib/bitcore/crypto/sigtype.js +18 -0
  51. package/dist/lib/bitcore/encoding/base58.d.ts +16 -0
  52. package/dist/lib/bitcore/encoding/base58.d.ts.map +1 -0
  53. package/dist/lib/bitcore/encoding/base58.js +55 -0
  54. package/dist/lib/bitcore/encoding/base58check.d.ts +9 -0
  55. package/dist/lib/bitcore/encoding/base58check.d.ts.map +1 -0
  56. package/dist/lib/bitcore/encoding/base58check.js +82 -0
  57. package/dist/lib/bitcore/encoding/bufferreader.d.ts +34 -0
  58. package/dist/lib/bitcore/encoding/bufferreader.d.ts.map +1 -0
  59. package/dist/lib/bitcore/encoding/bufferreader.js +198 -0
  60. package/dist/lib/bitcore/encoding/bufferwriter.d.ts +36 -0
  61. package/dist/lib/bitcore/encoding/bufferwriter.d.ts.map +1 -0
  62. package/dist/lib/bitcore/encoding/bufferwriter.js +189 -0
  63. package/dist/lib/bitcore/encoding/varint.d.ts +20 -0
  64. package/dist/lib/bitcore/encoding/varint.d.ts.map +1 -0
  65. package/dist/lib/bitcore/encoding/varint.js +61 -0
  66. package/dist/lib/bitcore/errors.d.ts +28 -0
  67. package/dist/lib/bitcore/errors.d.ts.map +1 -0
  68. package/dist/lib/bitcore/errors.js +325 -0
  69. package/dist/lib/bitcore/hdprivatekey.d.ts +78 -0
  70. package/dist/lib/bitcore/hdprivatekey.d.ts.map +1 -0
  71. package/dist/lib/bitcore/hdprivatekey.js +381 -0
  72. package/dist/lib/bitcore/hdpublickey.d.ts +98 -0
  73. package/dist/lib/bitcore/hdpublickey.d.ts.map +1 -0
  74. package/dist/lib/bitcore/hdpublickey.js +416 -0
  75. package/dist/lib/bitcore/index.d.ts +60 -0
  76. package/dist/lib/bitcore/index.d.ts.map +1 -0
  77. package/dist/lib/bitcore/index.js +44 -0
  78. package/dist/lib/bitcore/message.d.ts +23 -0
  79. package/dist/lib/bitcore/message.d.ts.map +1 -0
  80. package/dist/lib/bitcore/message.js +112 -0
  81. package/dist/lib/bitcore/mnemonic/errors.d.ts +7 -0
  82. package/dist/lib/bitcore/mnemonic/errors.d.ts.map +1 -0
  83. package/dist/lib/bitcore/mnemonic/errors.js +20 -0
  84. package/dist/lib/bitcore/mnemonic/index.d.ts +5 -0
  85. package/dist/lib/bitcore/mnemonic/index.d.ts.map +1 -0
  86. package/dist/lib/bitcore/mnemonic/index.js +4 -0
  87. package/dist/lib/bitcore/mnemonic/mnemonic.d.ts +23 -0
  88. package/dist/lib/bitcore/mnemonic/mnemonic.d.ts.map +1 -0
  89. package/dist/lib/bitcore/mnemonic/mnemonic.js +164 -0
  90. package/dist/lib/bitcore/mnemonic/pbkdf2.d.ts +2 -0
  91. package/dist/lib/bitcore/mnemonic/pbkdf2.d.ts.map +1 -0
  92. package/dist/lib/bitcore/mnemonic/pbkdf2.js +25 -0
  93. package/dist/lib/bitcore/mnemonic/words/english.d.ts +2 -0
  94. package/dist/lib/bitcore/mnemonic/words/english.d.ts.map +1 -0
  95. package/dist/lib/bitcore/mnemonic/words/english.js +2050 -0
  96. package/dist/lib/bitcore/mnemonic/words/index.d.ts +4 -0
  97. package/dist/lib/bitcore/mnemonic/words/index.d.ts.map +1 -0
  98. package/dist/lib/bitcore/mnemonic/words/index.js +4 -0
  99. package/dist/lib/bitcore/musig2/index.d.ts +3 -0
  100. package/dist/lib/bitcore/musig2/index.d.ts.map +1 -0
  101. package/dist/lib/bitcore/musig2/index.js +2 -0
  102. package/dist/lib/bitcore/musig2/session.d.ts +79 -0
  103. package/dist/lib/bitcore/musig2/session.d.ts.map +1 -0
  104. package/dist/lib/bitcore/musig2/session.js +346 -0
  105. package/dist/lib/bitcore/musig2/signer.d.ts +61 -0
  106. package/dist/lib/bitcore/musig2/signer.d.ts.map +1 -0
  107. package/dist/lib/bitcore/musig2/signer.js +146 -0
  108. package/dist/lib/bitcore/networks.d.ts +53 -0
  109. package/dist/lib/bitcore/networks.d.ts.map +1 -0
  110. package/dist/lib/bitcore/networks.js +150 -0
  111. package/dist/lib/bitcore/opcode.d.ts +250 -0
  112. package/dist/lib/bitcore/opcode.d.ts.map +1 -0
  113. package/dist/lib/bitcore/opcode.js +270 -0
  114. package/dist/lib/bitcore/privatekey.d.ts +56 -0
  115. package/dist/lib/bitcore/privatekey.d.ts.map +1 -0
  116. package/dist/lib/bitcore/privatekey.js +237 -0
  117. package/dist/lib/bitcore/publickey.d.ts +59 -0
  118. package/dist/lib/bitcore/publickey.d.ts.map +1 -0
  119. package/dist/lib/bitcore/publickey.js +263 -0
  120. package/dist/lib/bitcore/script/interpreter.d.ts +98 -0
  121. package/dist/lib/bitcore/script/interpreter.d.ts.map +1 -0
  122. package/dist/lib/bitcore/script/interpreter.js +1704 -0
  123. package/dist/lib/bitcore/script.d.ts +111 -0
  124. package/dist/lib/bitcore/script.d.ts.map +1 -0
  125. package/dist/lib/bitcore/script.js +1112 -0
  126. package/dist/lib/bitcore/taproot/musig2.d.ts +29 -0
  127. package/dist/lib/bitcore/taproot/musig2.d.ts.map +1 -0
  128. package/dist/lib/bitcore/taproot/musig2.js +104 -0
  129. package/dist/lib/bitcore/taproot/nft.d.ts +164 -0
  130. package/dist/lib/bitcore/taproot/nft.d.ts.map +1 -0
  131. package/dist/lib/bitcore/taproot/nft.js +407 -0
  132. package/dist/lib/bitcore/taproot.d.ts +65 -0
  133. package/dist/lib/bitcore/taproot.d.ts.map +1 -0
  134. package/dist/lib/bitcore/taproot.js +288 -0
  135. package/dist/lib/bitcore/transaction/index.d.ts +12 -0
  136. package/dist/lib/bitcore/transaction/index.d.ts.map +1 -0
  137. package/dist/lib/bitcore/transaction/index.js +6 -0
  138. package/dist/lib/bitcore/transaction/input.d.ts +202 -0
  139. package/dist/lib/bitcore/transaction/input.d.ts.map +1 -0
  140. package/dist/lib/bitcore/transaction/input.js +911 -0
  141. package/dist/lib/bitcore/transaction/output.d.ts +48 -0
  142. package/dist/lib/bitcore/transaction/output.d.ts.map +1 -0
  143. package/dist/lib/bitcore/transaction/output.js +231 -0
  144. package/dist/lib/bitcore/transaction/sighash.d.ts +32 -0
  145. package/dist/lib/bitcore/transaction/sighash.d.ts.map +1 -0
  146. package/dist/lib/bitcore/transaction/sighash.js +335 -0
  147. package/dist/lib/bitcore/transaction/signature.d.ts +36 -0
  148. package/dist/lib/bitcore/transaction/signature.d.ts.map +1 -0
  149. package/dist/lib/bitcore/transaction/signature.js +130 -0
  150. package/dist/lib/bitcore/transaction/transaction.d.ts +164 -0
  151. package/dist/lib/bitcore/transaction/transaction.d.ts.map +1 -0
  152. package/dist/lib/bitcore/transaction/transaction.js +1016 -0
  153. package/dist/lib/bitcore/transaction/unspentoutput.d.ts +58 -0
  154. package/dist/lib/bitcore/transaction/unspentoutput.d.ts.map +1 -0
  155. package/dist/lib/bitcore/transaction/unspentoutput.js +167 -0
  156. package/dist/lib/bitcore/unit.d.ts +44 -0
  157. package/dist/lib/bitcore/unit.d.ts.map +1 -0
  158. package/dist/lib/bitcore/unit.js +106 -0
  159. package/dist/lib/bitcore/uri.d.ts +29 -0
  160. package/dist/lib/bitcore/uri.d.ts.map +1 -0
  161. package/dist/lib/bitcore/uri.js +163 -0
  162. package/dist/lib/bitcore/util/base32.d.ts +5 -0
  163. package/dist/lib/bitcore/util/base32.d.ts.map +1 -0
  164. package/dist/lib/bitcore/util/base32.js +58 -0
  165. package/dist/lib/bitcore/util/buffer.d.ts +18 -0
  166. package/dist/lib/bitcore/util/buffer.d.ts.map +1 -0
  167. package/dist/lib/bitcore/util/buffer.js +76 -0
  168. package/dist/lib/bitcore/util/convertBits.d.ts +2 -0
  169. package/dist/lib/bitcore/util/convertBits.d.ts.map +1 -0
  170. package/dist/lib/bitcore/util/convertBits.js +26 -0
  171. package/dist/lib/bitcore/util/js.d.ts +9 -0
  172. package/dist/lib/bitcore/util/js.d.ts.map +1 -0
  173. package/dist/lib/bitcore/util/js.js +45 -0
  174. package/dist/lib/bitcore/util/preconditions.d.ts +6 -0
  175. package/dist/lib/bitcore/util/preconditions.d.ts.map +1 -0
  176. package/dist/lib/bitcore/util/preconditions.js +31 -0
  177. package/dist/lib/bitcore/util.d.ts +14 -0
  178. package/dist/lib/bitcore/util.d.ts.map +1 -0
  179. package/dist/lib/bitcore/util.js +13 -0
  180. package/dist/lib/bitcore/xaddress.d.ts +45 -0
  181. package/dist/lib/bitcore/xaddress.d.ts.map +1 -0
  182. package/dist/lib/bitcore/xaddress.js +279 -0
  183. package/dist/lib/rank/api.d.ts +75 -0
  184. package/dist/lib/rank/api.d.ts.map +1 -0
  185. package/dist/lib/rank/api.js +4 -0
  186. package/dist/lib/rank/index.d.ts +127 -0
  187. package/dist/lib/rank/index.d.ts.map +1 -0
  188. package/dist/lib/rank/index.js +421 -0
  189. package/dist/lib/rank/opcode.d.ts +23 -0
  190. package/dist/lib/rank/opcode.d.ts.map +1 -0
  191. package/dist/lib/rank/opcode.js +23 -0
  192. package/dist/lib/rank/script.d.ts +2 -0
  193. package/dist/lib/rank/script.d.ts.map +1 -0
  194. package/dist/lib/rank/script.js +7 -0
  195. package/dist/lib/rank/transaction.d.ts +3 -0
  196. package/dist/lib/rank/transaction.d.ts.map +1 -0
  197. package/dist/lib/rank/transaction.js +12 -0
  198. package/dist/lib/rpc.d.ts +136 -0
  199. package/dist/lib/rpc.d.ts.map +1 -0
  200. package/dist/lib/rpc.js +62 -0
  201. package/dist/utils/constants.d.ts +18 -0
  202. package/dist/utils/constants.d.ts.map +1 -0
  203. package/dist/utils/constants.js +20 -0
  204. package/dist/utils/env.d.ts +3 -0
  205. package/dist/utils/env.d.ts.map +1 -0
  206. package/dist/utils/env.js +8 -0
  207. package/dist/utils/string.d.ts +11 -0
  208. package/dist/utils/string.d.ts.map +1 -0
  209. package/dist/utils/string.js +47 -0
  210. package/dist/utils/types.d.ts +2 -0
  211. package/dist/utils/types.d.ts.map +1 -0
  212. package/dist/utils/types.js +1 -0
  213. package/dist/utils/wallet.d.ts +12 -0
  214. package/dist/utils/wallet.d.ts.map +1 -0
  215. package/dist/utils/wallet.js +28 -0
  216. package/package.json +91 -0
@@ -0,0 +1,58 @@
1
+ import { Script } from '../script.js';
2
+ import { Address } from '../address.js';
3
+ import { PublicKey } from '../publickey.js';
4
+ import { Unit } from '../unit.js';
5
+ import type { MuSigKeyAggContext } from '../crypto/musig2.js';
6
+ export interface UnspentOutputData {
7
+ txid?: string;
8
+ txId?: string;
9
+ vout?: number;
10
+ outputIndex?: number;
11
+ scriptPubKey?: Script | Buffer | string;
12
+ script?: Script | Buffer | string;
13
+ amount?: number;
14
+ satoshis?: number | bigint;
15
+ address?: Address | string;
16
+ internalPubKey?: PublicKey | Buffer | string;
17
+ merkleRoot?: Buffer;
18
+ keyAggContext?: MuSigKeyAggContext;
19
+ mySignerIndex?: number;
20
+ }
21
+ export interface UnspentOutputObject {
22
+ address?: string;
23
+ txid: string;
24
+ vout: number;
25
+ scriptPubKey: string;
26
+ amount: number;
27
+ }
28
+ export declare class UnspentOutput {
29
+ readonly address?: Address;
30
+ readonly txId: string;
31
+ readonly outputIndex: number;
32
+ readonly script: Script;
33
+ readonly satoshis: number;
34
+ readonly internalPubKey?: PublicKey;
35
+ readonly merkleRoot?: Buffer;
36
+ readonly keyAggContext?: MuSigKeyAggContext;
37
+ readonly mySignerIndex?: number;
38
+ constructor(data: UnspentOutputData);
39
+ getXPI(): number;
40
+ getUnit(): Unit;
41
+ isValid(): boolean;
42
+ isDust(dustThreshold?: number): boolean;
43
+ toObject(): UnspentOutputObject;
44
+ toJSON: () => UnspentOutputObject;
45
+ inspect(): string;
46
+ clone(): UnspentOutput;
47
+ toString(): string;
48
+ isPayToPublicKeyHash(): boolean;
49
+ isPayToScriptHash(): boolean;
50
+ getAddress(): string | null;
51
+ static fromObject(obj: UnspentOutputData): UnspentOutput;
52
+ static fromObjects(objects: UnspentOutputData[]): UnspentOutput[];
53
+ static filterByAddress(unspentOutputs: UnspentOutput[], address: string | Address): UnspentOutput[];
54
+ static filterByMinAmount(unspentOutputs: UnspentOutput[], minAmount: number | bigint): UnspentOutput[];
55
+ static calculateTotal(unspentOutputs: UnspentOutput[]): number;
56
+ static selectForAmount(unspentOutputs: UnspentOutput[], targetAmount: number | bigint): UnspentOutput[];
57
+ }
58
+ //# sourceMappingURL=unspentoutput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unspentoutput.d.ts","sourceRoot":"","sources":["../../../../lib/bitcore/transaction/unspentoutput.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,167 @@
1
+ import { Preconditions } from '../util/preconditions.js';
2
+ import { JSUtil } from '../util/js.js';
3
+ import { Script } from '../script.js';
4
+ import { Address } from '../address.js';
5
+ import { PublicKey } from '../publickey.js';
6
+ import { Unit } from '../unit.js';
7
+ export class UnspentOutput {
8
+ address;
9
+ txId;
10
+ outputIndex;
11
+ script;
12
+ satoshis;
13
+ internalPubKey;
14
+ merkleRoot;
15
+ keyAggContext;
16
+ mySignerIndex;
17
+ constructor(data) {
18
+ Preconditions.checkArgument(typeof data === 'object' && data !== null, 'Must provide an object from where to extract data');
19
+ const address = data.address ? new Address(data.address) : undefined;
20
+ const txId = data.txid || data.txId;
21
+ if (!txId || !JSUtil.isHexaString(txId) || txId.length > 64) {
22
+ throw new Error('Invalid TXID in object: ' + JSON.stringify(data));
23
+ }
24
+ const outputIndex = data.vout !== undefined ? data.vout : data.outputIndex;
25
+ if (typeof outputIndex !== 'number') {
26
+ throw new Error('Invalid outputIndex, received ' + outputIndex);
27
+ }
28
+ Preconditions.checkArgument(data.scriptPubKey !== undefined || data.script !== undefined, 'Must provide the scriptPubKey for that output!');
29
+ const script = new Script(data.scriptPubKey || data.script);
30
+ Preconditions.checkArgument(data.amount !== undefined || data.satoshis !== undefined, 'Must provide an amount for the output');
31
+ let amount;
32
+ if (data.amount !== undefined) {
33
+ amount = Number(Unit.fromXPI(data.amount).toSatoshis());
34
+ }
35
+ else if (data.satoshis !== undefined) {
36
+ amount =
37
+ typeof data.satoshis === 'bigint'
38
+ ? Number(data.satoshis)
39
+ : data.satoshis;
40
+ }
41
+ else {
42
+ throw new Error('No amount provided');
43
+ }
44
+ Preconditions.checkArgument(typeof amount === 'number', 'Amount must be a number');
45
+ this.address = address;
46
+ this.txId = txId;
47
+ this.outputIndex = outputIndex;
48
+ this.script = script;
49
+ this.satoshis = amount;
50
+ if (data.internalPubKey) {
51
+ if (data.internalPubKey instanceof PublicKey) {
52
+ this.internalPubKey = data.internalPubKey;
53
+ }
54
+ else if (Buffer.isBuffer(data.internalPubKey)) {
55
+ this.internalPubKey = new PublicKey(data.internalPubKey);
56
+ }
57
+ else if (typeof data.internalPubKey === 'string') {
58
+ this.internalPubKey = new PublicKey(data.internalPubKey);
59
+ }
60
+ }
61
+ this.merkleRoot = data.merkleRoot;
62
+ this.keyAggContext = data.keyAggContext;
63
+ this.mySignerIndex = data.mySignerIndex;
64
+ }
65
+ getXPI() {
66
+ return this.satoshis / 1000000;
67
+ }
68
+ getUnit() {
69
+ return Unit.fromSatoshis(this.satoshis);
70
+ }
71
+ isValid() {
72
+ return (JSUtil.isHexaString(this.txId) &&
73
+ this.txId.length === 64 &&
74
+ this.outputIndex >= 0 &&
75
+ this.satoshis > 0 &&
76
+ this.script.isValid());
77
+ }
78
+ isDust(dustThreshold = 546) {
79
+ return this.satoshis < dustThreshold;
80
+ }
81
+ toObject() {
82
+ return {
83
+ address: this.address ? this.address.toString() : undefined,
84
+ txid: this.txId,
85
+ vout: this.outputIndex,
86
+ scriptPubKey: this.script.toBuffer().toString('hex'),
87
+ amount: Unit.fromSatoshis(this.satoshis).toXPI(),
88
+ };
89
+ }
90
+ toJSON = this.toObject;
91
+ inspect() {
92
+ return ('<UnspentOutput: ' +
93
+ this.txId +
94
+ ':' +
95
+ this.outputIndex +
96
+ ', satoshis: ' +
97
+ this.satoshis +
98
+ ', address: ' +
99
+ this.address +
100
+ '>');
101
+ }
102
+ clone() {
103
+ return new UnspentOutput({
104
+ txId: this.txId,
105
+ outputIndex: this.outputIndex,
106
+ script: this.script.clone(),
107
+ satoshis: this.satoshis,
108
+ address: this.address,
109
+ internalPubKey: this.internalPubKey,
110
+ merkleRoot: this.merkleRoot,
111
+ keyAggContext: this.keyAggContext,
112
+ mySignerIndex: this.mySignerIndex,
113
+ });
114
+ }
115
+ toString() {
116
+ return this.txId + ':' + this.outputIndex;
117
+ }
118
+ isPayToPublicKeyHash() {
119
+ return this.script.isPayToPublicKeyHash();
120
+ }
121
+ isPayToScriptHash() {
122
+ return this.script.isPayToScriptHash();
123
+ }
124
+ getAddress() {
125
+ try {
126
+ const addressInfo = this.script.getAddressInfo();
127
+ return addressInfo ? addressInfo.toString() : null;
128
+ }
129
+ catch (e) {
130
+ return null;
131
+ }
132
+ }
133
+ static fromObject(obj) {
134
+ return new UnspentOutput(obj);
135
+ }
136
+ static fromObjects(objects) {
137
+ return objects.map(obj => new UnspentOutput(obj));
138
+ }
139
+ static filterByAddress(unspentOutputs, address) {
140
+ const addressStr = typeof address === 'string' ? address : address.toString();
141
+ return unspentOutputs.filter(utxo => {
142
+ const utxoAddress = utxo.getAddress();
143
+ return utxoAddress === addressStr;
144
+ });
145
+ }
146
+ static filterByMinAmount(unspentOutputs, minAmount) {
147
+ const minSatoshis = typeof minAmount === 'bigint' ? Number(minAmount) : minAmount;
148
+ return unspentOutputs.filter(utxo => utxo.satoshis >= minSatoshis);
149
+ }
150
+ static calculateTotal(unspentOutputs) {
151
+ return unspentOutputs.reduce((total, utxo) => total + utxo.satoshis, 0);
152
+ }
153
+ static selectForAmount(unspentOutputs, targetAmount) {
154
+ const targetSatoshis = typeof targetAmount === 'bigint' ? Number(targetAmount) : targetAmount;
155
+ const selected = [];
156
+ let total = 0;
157
+ const sorted = [...unspentOutputs].sort((a, b) => b.satoshis - a.satoshis);
158
+ for (const utxo of sorted) {
159
+ selected.push(utxo);
160
+ total += utxo.satoshis;
161
+ if (total >= targetSatoshis) {
162
+ break;
163
+ }
164
+ }
165
+ return selected;
166
+ }
167
+ }
@@ -0,0 +1,44 @@
1
+ declare const UNITS: {
2
+ readonly XPI: readonly [1000000, 6];
3
+ readonly mXPI: readonly [1000, 3];
4
+ readonly uXPI: readonly [100, 2];
5
+ readonly bits: readonly [100, 2];
6
+ readonly satoshis: readonly [1, 0];
7
+ };
8
+ export interface UnitData {
9
+ amount: number;
10
+ code: string;
11
+ }
12
+ export type UnitCode = keyof typeof UNITS;
13
+ export declare class Unit {
14
+ private _value;
15
+ static readonly XPI = "XPI";
16
+ static readonly mXPI = "mXPI";
17
+ static readonly uXPI = "uXPI";
18
+ static readonly bits = "bits";
19
+ static readonly satoshis = "satoshis";
20
+ constructor(amount: number, code: UnitCode | number);
21
+ static fromObject(data: UnitData): Unit;
22
+ static fromXPI(amount: number): Unit;
23
+ static fromMillis(amount: number): Unit;
24
+ static fromMilis: typeof Unit.fromMillis;
25
+ static fromMicros(amount: number): Unit;
26
+ static fromBits: typeof Unit.fromMicros;
27
+ static fromSatoshis(amount: number | bigint): Unit;
28
+ static fromFiat(amount: number, rate: number): Unit;
29
+ private _from;
30
+ to(code: UnitCode | number): number;
31
+ toXPI(): number;
32
+ toMillis(): number;
33
+ toMilis: () => number;
34
+ toMicros(): number;
35
+ toBits: () => number;
36
+ toSatoshis(): bigint;
37
+ atRate(rate: number): number;
38
+ toString(): string;
39
+ toObject(): UnitData;
40
+ toJSON: () => UnitData;
41
+ inspect(): string;
42
+ }
43
+ export {};
44
+ //# sourceMappingURL=unit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unit.d.ts","sourceRoot":"","sources":["../../../lib/bitcore/unit.ts"],"names":[],"mappings":"AAwBA,QAAA,MAAM,KAAK;;;;;;CAMD,CAAA;AAEV,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,KAAK,CAAA;AA0BzC,qBAAa,IAAI;IACf,OAAO,CAAC,MAAM,CAAS;IAGvB,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAQ;IAC3B,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAS;IAC7B,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAS;IAC7B,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAS;IAC7B,MAAM,CAAC,QAAQ,CAAC,QAAQ,cAAa;gBAEzB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM;IA2BnD,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI;IAevC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAUpC,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAOvC,MAAM,CAAC,SAAS,yBAAkB;IAQlC,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAOvC,MAAM,CAAC,QAAQ,yBAAkB;IAQjC,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAclD,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAInD,OAAO,CAAC,KAAK;IAab,EAAE,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM;IAuBnC,KAAK,IAAI,MAAM;IASf,QAAQ,IAAI,MAAM;IAOlB,OAAO,QAPK,MAAM,CAOK;IAOvB,QAAQ,IAAI,MAAM;IAOlB,MAAM,QAPM,MAAM,CAOI;IAOtB,UAAU,IAAI,MAAM;IAUpB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAS5B,QAAQ,IAAI,MAAM;IASlB,QAAQ,IAAI,QAAQ;IAUpB,MAAM,QAVM,QAAQ,CAUE;IAOtB,OAAO,IAAI,MAAM;CAGlB"}
@@ -0,0 +1,106 @@
1
+ import { Preconditions } from './util/preconditions.js';
2
+ const UNITS = {
3
+ XPI: [1e6, 6],
4
+ mXPI: [1e3, 3],
5
+ uXPI: [1e2, 2],
6
+ bits: [1e2, 2],
7
+ satoshis: [1, 0],
8
+ };
9
+ export class Unit {
10
+ _value;
11
+ static XPI = 'XPI';
12
+ static mXPI = 'mXPI';
13
+ static uXPI = 'uXPI';
14
+ static bits = 'bits';
15
+ static satoshis = 'satoshis';
16
+ constructor(amount, code) {
17
+ if (typeof code === 'number') {
18
+ if (code <= 0) {
19
+ throw new Error(`Invalid exchange rate: ${code}`);
20
+ }
21
+ amount = amount / code;
22
+ code = Unit.XPI;
23
+ }
24
+ this._value = this._from(amount, code);
25
+ Object.keys(UNITS).forEach(key => {
26
+ Object.defineProperty(this, key, {
27
+ get: () => this.to(key),
28
+ enumerable: true,
29
+ });
30
+ });
31
+ }
32
+ static fromObject(data) {
33
+ Preconditions.checkArgument(typeof data === 'object', 'data', 'Argument is expected to be an object');
34
+ return new Unit(data.amount, data.code);
35
+ }
36
+ static fromXPI(amount) {
37
+ return new Unit(amount, Unit.XPI);
38
+ }
39
+ static fromMillis(amount) {
40
+ return new Unit(amount, Unit.mXPI);
41
+ }
42
+ static fromMilis = Unit.fromMillis;
43
+ static fromMicros(amount) {
44
+ return new Unit(amount, Unit.bits);
45
+ }
46
+ static fromBits = Unit.fromMicros;
47
+ static fromSatoshis(amount) {
48
+ if (typeof amount === 'bigint') {
49
+ return new Unit(Number(amount), Unit.satoshis);
50
+ }
51
+ return new Unit(amount, Unit.satoshis);
52
+ }
53
+ static fromFiat(amount, rate) {
54
+ return new Unit(amount, rate);
55
+ }
56
+ _from(amount, code) {
57
+ if (!UNITS[code]) {
58
+ throw new Error(`Unrecognized unit code: ${code}`);
59
+ }
60
+ return BigInt(Math.round(amount * UNITS[code][0]));
61
+ }
62
+ to(code) {
63
+ if (typeof code === 'number') {
64
+ if (code <= 0) {
65
+ throw new Error(`Invalid exchange rate: ${code}`);
66
+ }
67
+ return parseFloat((this.to(Unit.XPI) * code).toFixed(2));
68
+ }
69
+ if (!UNITS[code]) {
70
+ throw new Error(`Unrecognized unit code: ${code}`);
71
+ }
72
+ const divisor = BigInt(UNITS[code][0]);
73
+ const value = Number(this._value) / Number(divisor);
74
+ return parseFloat(value.toFixed(UNITS[code][1]));
75
+ }
76
+ toXPI() {
77
+ return this.to(Unit.XPI);
78
+ }
79
+ toMillis() {
80
+ return this.to(Unit.mXPI);
81
+ }
82
+ toMilis = this.toMillis;
83
+ toMicros() {
84
+ return this.to(Unit.bits);
85
+ }
86
+ toBits = this.toMicros;
87
+ toSatoshis() {
88
+ return this._value;
89
+ }
90
+ atRate(rate) {
91
+ return this.to(rate);
92
+ }
93
+ toString() {
94
+ return this._value.toString() + ' satoshis';
95
+ }
96
+ toObject() {
97
+ return {
98
+ amount: this.to(Unit.XPI),
99
+ code: Unit.XPI,
100
+ };
101
+ }
102
+ toJSON = this.toObject;
103
+ inspect() {
104
+ return '<Unit: ' + this.toString() + '>';
105
+ }
106
+ }
@@ -0,0 +1,29 @@
1
+ import { Address } from './address.js';
2
+ export interface URIParams {
3
+ address?: string;
4
+ amount?: number;
5
+ label?: string;
6
+ message?: string;
7
+ [key: string]: string | number | undefined;
8
+ }
9
+ export declare class URI {
10
+ private _address?;
11
+ private _amount?;
12
+ private _label?;
13
+ private _message?;
14
+ private _otherParams;
15
+ constructor(data: string | URIParams, knownParams?: string[]);
16
+ static fromString(data: string): URI;
17
+ static fromObject(data: URIParams): URI;
18
+ static isValid(data: string | URIParams, knownParams?: string[]): boolean;
19
+ private _fromString;
20
+ private _fromObject;
21
+ get address(): Address | undefined;
22
+ get amount(): number | undefined;
23
+ get label(): string | undefined;
24
+ get message(): string | undefined;
25
+ get otherParams(): Record<string, string>;
26
+ toString(prefix?: string): string;
27
+ toObject(): URIParams;
28
+ }
29
+ //# sourceMappingURL=uri.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uri.d.ts","sourceRoot":"","sources":["../../../lib/bitcore/uri.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAQtC,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CAC3C;AAED,qBAAa,GAAG;IACd,OAAO,CAAC,QAAQ,CAAC,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAC,CAAQ;IACxB,OAAO,CAAC,MAAM,CAAC,CAAQ;IACvB,OAAO,CAAC,QAAQ,CAAC,CAAQ;IACzB,OAAO,CAAC,YAAY,CAA6B;gBAErC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE;IAa5D,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG;IAOpC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,GAAG,GAAG;IAOvC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO;IASzE,OAAO,CAAC,WAAW;IAiDnB,OAAO,CAAC,WAAW;IAgCnB,IAAI,OAAO,IAAI,OAAO,GAAG,SAAS,CAEjC;IAKD,IAAI,MAAM,IAAI,MAAM,GAAG,SAAS,CAE/B;IAKD,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAE9B;IAKD,IAAI,OAAO,IAAI,MAAM,GAAG,SAAS,CAEhC;IAKD,IAAI,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAExC;IAKD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;IAuCjC,QAAQ,IAAI,SAAS;CA0BtB"}
@@ -0,0 +1,163 @@
1
+ import { Address } from './address.js';
2
+ const DEFAULT_PREFIX = 'giveto:';
3
+ const URI_PREFIXES = [DEFAULT_PREFIX];
4
+ export class URI {
5
+ _address;
6
+ _amount;
7
+ _label;
8
+ _message;
9
+ _otherParams = {};
10
+ constructor(data, knownParams) {
11
+ if (typeof data === 'string') {
12
+ this._fromString(data, knownParams);
13
+ }
14
+ else if (typeof data === 'object') {
15
+ this._fromObject(data);
16
+ }
17
+ else {
18
+ throw new Error('Invalid URI data');
19
+ }
20
+ }
21
+ static fromString(data) {
22
+ return new URI(data);
23
+ }
24
+ static fromObject(data) {
25
+ return new URI(data);
26
+ }
27
+ static isValid(data, knownParams) {
28
+ try {
29
+ new URI(data, knownParams);
30
+ return true;
31
+ }
32
+ catch (e) {
33
+ return false;
34
+ }
35
+ }
36
+ _fromString(uriString, knownParams) {
37
+ const index = URI_PREFIXES.findIndex(prefix => uriString.startsWith(prefix));
38
+ if (index === -1) {
39
+ throw new Error('Invalid Lotus URI');
40
+ }
41
+ const prefix = URI_PREFIXES[index];
42
+ const uri = uriString.substring(prefix.length);
43
+ const parts = uri.split('?');
44
+ if (parts.length === 0) {
45
+ throw new Error('Invalid Lotus URI format');
46
+ }
47
+ const addressPart = parts[0];
48
+ if (addressPart) {
49
+ try {
50
+ this._address = Address.fromString(addressPart);
51
+ }
52
+ catch (e) {
53
+ throw new Error('Invalid Lotus address in URI');
54
+ }
55
+ }
56
+ if (parts.length > 1) {
57
+ const queryString = parts[1];
58
+ const params = new URLSearchParams(queryString);
59
+ for (const [key, value] of params) {
60
+ switch (key) {
61
+ case 'amount':
62
+ this._amount = parseFloat(value);
63
+ break;
64
+ case 'label':
65
+ this._label = decodeURIComponent(value);
66
+ break;
67
+ case 'message':
68
+ this._message = decodeURIComponent(value);
69
+ break;
70
+ default:
71
+ if (!knownParams || knownParams.includes(key)) {
72
+ this._otherParams[key] = decodeURIComponent(value);
73
+ }
74
+ break;
75
+ }
76
+ }
77
+ }
78
+ }
79
+ _fromObject(data) {
80
+ if (data.address) {
81
+ try {
82
+ this._address = Address.fromString(data.address);
83
+ }
84
+ catch (e) {
85
+ throw new Error('Invalid Lotus address');
86
+ }
87
+ }
88
+ if (data.amount !== undefined) {
89
+ this._amount = data.amount;
90
+ }
91
+ if (data.label) {
92
+ this._label = data.label;
93
+ }
94
+ if (data.message) {
95
+ this._message = data.message;
96
+ }
97
+ Object.keys(data).forEach(key => {
98
+ if (!['address', 'amount', 'label', 'message'].includes(key)) {
99
+ this._otherParams[key] = String(data[key]);
100
+ }
101
+ });
102
+ }
103
+ get address() {
104
+ return this._address;
105
+ }
106
+ get amount() {
107
+ return this._amount;
108
+ }
109
+ get label() {
110
+ return this._label;
111
+ }
112
+ get message() {
113
+ return this._message;
114
+ }
115
+ get otherParams() {
116
+ return { ...this._otherParams };
117
+ }
118
+ toString(prefix) {
119
+ if (!this._address) {
120
+ throw new Error('Cannot convert URI to string without address');
121
+ }
122
+ if (prefix && !URI_PREFIXES.includes(prefix)) {
123
+ throw new Error('Invalid URI prefix specified');
124
+ }
125
+ let uri = `${prefix ?? DEFAULT_PREFIX}${this._address.toString()}`;
126
+ const params = [];
127
+ if (this._amount !== undefined) {
128
+ params.push(`amount=${this._amount}`);
129
+ }
130
+ if (this._label) {
131
+ params.push(`label=${encodeURIComponent(this._label)}`);
132
+ }
133
+ if (this._message) {
134
+ params.push(`message=${encodeURIComponent(this._message)}`);
135
+ }
136
+ Object.keys(this._otherParams).forEach(key => {
137
+ params.push(`${key}=${encodeURIComponent(this._otherParams[key])}`);
138
+ });
139
+ if (params.length > 0) {
140
+ uri += '?' + params.join('&');
141
+ }
142
+ return uri;
143
+ }
144
+ toObject() {
145
+ const obj = {};
146
+ if (this._address) {
147
+ obj.address = this._address.toString();
148
+ }
149
+ if (this._amount !== undefined) {
150
+ obj.amount = this._amount;
151
+ }
152
+ if (this._label) {
153
+ obj.label = this._label;
154
+ }
155
+ if (this._message) {
156
+ obj.message = this._message;
157
+ }
158
+ Object.keys(this._otherParams).forEach(key => {
159
+ obj[key] = this._otherParams[key];
160
+ });
161
+ return obj;
162
+ }
163
+ }
@@ -0,0 +1,5 @@
1
+ export declare class Base32 {
2
+ static encode(data: number[]): string;
3
+ static decode(base32: string): number[];
4
+ }
5
+ //# sourceMappingURL=base32.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base32.d.ts","sourceRoot":"","sources":["../../../../lib/bitcore/util/base32.ts"],"names":[],"mappings":"AAkDA,qBAAa,MAAM;IAMjB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM;IAoBrC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;CAkBxC"}
@@ -0,0 +1,58 @@
1
+ import { Preconditions } from './preconditions.js';
2
+ const CHARSET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l';
3
+ const CHARSET_INVERSE_INDEX = {
4
+ 'q': 0,
5
+ 'p': 1,
6
+ 'z': 2,
7
+ 'r': 3,
8
+ 'y': 4,
9
+ '9': 5,
10
+ 'x': 6,
11
+ '8': 7,
12
+ 'g': 8,
13
+ 'f': 9,
14
+ '2': 10,
15
+ 't': 11,
16
+ 'v': 12,
17
+ 'd': 13,
18
+ 'w': 14,
19
+ '0': 15,
20
+ 's': 16,
21
+ '3': 17,
22
+ 'j': 18,
23
+ 'n': 19,
24
+ '5': 20,
25
+ '4': 21,
26
+ 'k': 22,
27
+ 'h': 23,
28
+ 'c': 24,
29
+ 'e': 25,
30
+ '6': 26,
31
+ 'm': 27,
32
+ 'u': 28,
33
+ 'a': 29,
34
+ '7': 30,
35
+ 'l': 31,
36
+ };
37
+ export class Base32 {
38
+ static encode(data) {
39
+ Preconditions.checkArgument(Array.isArray(data), 'data', 'Must be Array');
40
+ let base32 = '';
41
+ for (let i = 0; i < data.length; i++) {
42
+ const value = data[i];
43
+ Preconditions.checkArgument(0 <= value && value < 32, 'value', `value ${value}`);
44
+ base32 += CHARSET[value];
45
+ }
46
+ return base32;
47
+ }
48
+ static decode(base32) {
49
+ Preconditions.checkArgument(typeof base32 === 'string', 'base32', 'Must be base32-encoded string');
50
+ const data = [];
51
+ for (let i = 0; i < base32.length; i++) {
52
+ const value = base32[i];
53
+ Preconditions.checkArgument(value in CHARSET_INVERSE_INDEX, 'value', `value ${value}`);
54
+ data.push(CHARSET_INVERSE_INDEX[value]);
55
+ }
56
+ return data;
57
+ }
58
+ }
@@ -0,0 +1,18 @@
1
+ export declare class BufferUtil {
2
+ static fill(buffer: Buffer, value: number): Buffer;
3
+ static copy(original: Buffer): Buffer;
4
+ static isBuffer(arg: unknown): arg is Buffer | Uint8Array;
5
+ static emptyBuffer(bytes: number): Buffer;
6
+ static concat(list: ReadonlyArray<Buffer>, totalLength?: number): Buffer;
7
+ static equals(a: Buffer, b: Buffer): boolean;
8
+ static equal(a: Buffer, b: Buffer): boolean;
9
+ static integerAsSingleByteBuffer(integer: number): Buffer;
10
+ static integerAsBuffer(integer: number): Buffer;
11
+ static integerFromBuffer(buffer: Buffer): number;
12
+ static integerFromSingleByteBuffer(buffer: Buffer): number;
13
+ static bufferToHex(buffer: Buffer): string;
14
+ static reverse(param: Buffer): Buffer;
15
+ }
16
+ export declare const NULL_HASH: Buffer<ArrayBufferLike>;
17
+ export declare const EMPTY_BUFFER: Buffer<ArrayBuffer>;
18
+ //# sourceMappingURL=buffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../../../../lib/bitcore/util/buffer.ts"],"names":[],"mappings":"AAOA,qBAAa,UAAU;IAQrB,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAgBlD,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAarC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,GAAG,UAAU;IAUzD,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAczC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM;IAOxE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO;IAgB5C,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO;IAU3C,MAAM,CAAC,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAWzD,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAgB/C,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAUhD,MAAM,CAAC,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAa1D,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAU1C,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAGtC;AAGD,eAAO,MAAM,SAAS,yBAAuC,CAAA;AAC7D,eAAO,MAAM,YAAY,qBAAkB,CAAA"}