@buildonspark/spark-sdk 0.1.46 → 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 (171) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/{chunk-BGGEVUJK.js → chunk-2ENZX6LT.js} +241 -7
  3. package/dist/{chunk-LHRD2WT6.js → chunk-4JD4HIAN.js} +23 -3
  4. package/dist/{chunk-I54FARY2.js → chunk-CDLETEDT.js} +11 -3
  5. package/dist/{chunk-OBFKIEMP.js → chunk-TM6CHQXC.js} +1 -1
  6. package/dist/chunk-UDK3EBE5.js +13514 -0
  7. package/dist/chunk-XYTKKLCV.js +7 -0
  8. package/dist/{RequestLightningSendInput-2cSh_In4.d.cts → client-DKbwpcnl.d.ts} +434 -212
  9. package/dist/{RequestLightningSendInput-CN6BNg_g.d.ts → client-Drs5Lapg.d.cts} +434 -212
  10. package/dist/{services/config.cjs → debug.cjs} +31007 -1003
  11. package/dist/debug.d.cts +126 -0
  12. package/dist/debug.d.ts +126 -0
  13. package/dist/debug.js +21 -0
  14. package/dist/graphql/objects/index.d.cts +4 -11
  15. package/dist/graphql/objects/index.d.ts +4 -11
  16. package/dist/graphql/objects/index.js +2 -4
  17. package/dist/index.cjs +18219 -20818
  18. package/dist/index.d.cts +15 -768
  19. package/dist/index.d.ts +15 -768
  20. package/dist/index.js +82 -76
  21. package/dist/index.node.cjs +23831 -26538
  22. package/dist/index.node.d.cts +191 -33
  23. package/dist/index.node.d.ts +191 -33
  24. package/dist/index.node.js +87 -181
  25. package/dist/native/index.cjs +17835 -20519
  26. package/dist/native/index.d.cts +1466 -1546
  27. package/dist/native/index.d.ts +1466 -1546
  28. package/dist/native/index.js +22605 -25286
  29. package/dist/proto/lrc20.d.cts +2 -2
  30. package/dist/proto/lrc20.d.ts +2 -2
  31. package/dist/proto/lrc20.js +3098 -46
  32. package/dist/proto/spark.cjs +241 -7
  33. package/dist/proto/spark.d.cts +1 -1
  34. package/dist/proto/spark.d.ts +1 -1
  35. package/dist/proto/spark.js +5 -1
  36. package/dist/proto/spark_token.cjs +22 -2
  37. package/dist/proto/spark_token.d.cts +8 -1
  38. package/dist/proto/spark_token.d.ts +8 -1
  39. package/dist/proto/spark_token.js +2 -2
  40. package/dist/{sdk-types-CKBsylfW.d.ts → sdk-types-DCIVdKUT.d.ts} +1 -1
  41. package/dist/{sdk-types-Ct8xmN7l.d.cts → sdk-types-DJ2ve9YY.d.cts} +1 -1
  42. package/dist/{spark-DbzGfse6.d.ts → spark-BUOx3U7Q.d.cts} +103 -5
  43. package/dist/{spark-DbzGfse6.d.cts → spark-BUOx3U7Q.d.ts} +103 -5
  44. package/dist/spark-wallet-CF8Oxjqs.d.ts +935 -0
  45. package/dist/spark-wallet-DOLSa3oF.d.cts +935 -0
  46. package/dist/spark_bindings/native/index.d.cts +1 -1
  47. package/dist/spark_bindings/native/index.d.ts +1 -1
  48. package/dist/spark_bindings/wasm/index.d.cts +1 -1
  49. package/dist/spark_bindings/wasm/index.d.ts +1 -1
  50. package/dist/{services/index.cjs → tests/test-utils.cjs} +9788 -10263
  51. package/dist/tests/test-utils.d.cts +79 -0
  52. package/dist/tests/test-utils.d.ts +79 -0
  53. package/dist/tests/test-utils.js +93 -0
  54. package/dist/types/index.cjs +239 -7
  55. package/dist/types/index.d.cts +5 -9
  56. package/dist/types/index.d.ts +5 -9
  57. package/dist/types/index.js +4 -6
  58. package/dist/{types-C-Rp0Oo7.d.ts → types-BADxR3bm.d.cts} +1 -1
  59. package/dist/{types-C-Rp0Oo7.d.cts → types-BADxR3bm.d.ts} +1 -1
  60. package/dist/{index-COm59SPw.d.ts → xchain-address-C2xMs9nz.d.cts} +6 -94
  61. package/dist/{index-CKL5DodV.d.cts → xchain-address-Ckto9oEz.d.ts} +6 -94
  62. package/package.json +9 -33
  63. package/src/debug.ts +13 -0
  64. package/src/graphql/client.ts +59 -20
  65. package/src/index.node.ts +28 -2
  66. package/src/index.ts +31 -1
  67. package/src/native/index.ts +16 -2
  68. package/src/proto/mock.ts +76 -0
  69. package/src/proto/spark.ts +354 -6
  70. package/src/proto/spark_token.ts +34 -2
  71. package/src/services/config.ts +4 -6
  72. package/src/services/connection.ts +131 -64
  73. package/src/services/coop-exit.ts +6 -3
  74. package/src/services/deposit.ts +9 -8
  75. package/src/services/lightning.ts +4 -3
  76. package/src/services/signing.ts +10 -6
  77. package/src/services/token-transactions.ts +100 -85
  78. package/src/services/transfer.ts +88 -60
  79. package/src/services/tree-creation.ts +17 -9
  80. package/src/services/wallet-config.ts +17 -9
  81. package/src/signer/signer.react-native.ts +5 -10
  82. package/src/signer/signer.ts +269 -339
  83. package/src/signer/types.ts +63 -0
  84. package/src/spark-wallet/spark-wallet.ts +226 -149
  85. package/src/spark-wallet/types.ts +22 -8
  86. package/src/tests/integration/adaptor-signature.test.ts +8 -9
  87. package/src/tests/integration/coop-exit.test.ts +214 -202
  88. package/src/tests/integration/lightning.test.ts +128 -103
  89. package/src/tests/integration/swap.test.ts +116 -84
  90. package/src/tests/integration/transfer.test.ts +291 -214
  91. package/src/tests/integration/tree-creation.test.ts +0 -5
  92. package/src/tests/integration/wallet.test.ts +1 -0
  93. package/src/tests/isHermeticTest.ts +3 -24
  94. package/src/tests/{test-util.ts → test-utils.ts} +13 -11
  95. package/src/tests/token-identifier.test.ts +6 -6
  96. package/src/tests/wrapWithOtelSpan.test.ts +1 -1
  97. package/src/{address → utils}/address.ts +1 -1
  98. package/src/utils/crypto.ts +19 -9
  99. package/src/utils/index.ts +2 -0
  100. package/src/utils/network.ts +17 -0
  101. package/src/utils/secret-sharing.ts +1 -2
  102. package/src/utils/signing.ts +1 -1
  103. package/src/utils/token-identifier.ts +27 -21
  104. package/src/utils/token-transaction-validation.ts +34 -0
  105. package/src/utils/token-transactions.ts +12 -8
  106. package/src/utils/unilateral-exit.ts +32 -0
  107. package/src/utils/xchain-address.ts +1 -1
  108. package/dist/BitcoinNetwork-TnABML0T.d.cts +0 -18
  109. package/dist/BitcoinNetwork-TnABML0T.d.ts +0 -18
  110. package/dist/LightningSendFeeEstimateInput-BgOhEAI-.d.cts +0 -10
  111. package/dist/LightningSendFeeEstimateInput-BgOhEAI-.d.ts +0 -10
  112. package/dist/address/index.cjs +0 -458
  113. package/dist/address/index.d.cts +0 -32
  114. package/dist/address/index.d.ts +0 -32
  115. package/dist/address/index.js +0 -17
  116. package/dist/chunk-4EMV7HHW.js +0 -277
  117. package/dist/chunk-C2S227QR.js +0 -2336
  118. package/dist/chunk-DXR2PXJU.js +0 -1122
  119. package/dist/chunk-GSI4OLXZ.js +0 -117
  120. package/dist/chunk-HHNQ3ZHC.js +0 -170
  121. package/dist/chunk-HMLOC6TE.js +0 -14
  122. package/dist/chunk-HSCLBJEL.js +0 -113
  123. package/dist/chunk-HWJWKEIU.js +0 -75
  124. package/dist/chunk-JB64OQES.js +0 -7095
  125. package/dist/chunk-KMUMFYFX.js +0 -137
  126. package/dist/chunk-N5VZVCGJ.js +0 -622
  127. package/dist/chunk-NSJF5F5O.js +0 -325
  128. package/dist/chunk-NTFKFRQ2.js +0 -3146
  129. package/dist/chunk-OFCJFZ4I.js +0 -24
  130. package/dist/chunk-QNNSEJ4P.js +0 -232
  131. package/dist/chunk-UXDODSDT.js +0 -838
  132. package/dist/chunk-VTUGIIWI.js +0 -0
  133. package/dist/chunk-Z5HIAYFT.js +0 -84
  134. package/dist/network-Css46DAz.d.cts +0 -46
  135. package/dist/network-hynb7iTZ.d.ts +0 -46
  136. package/dist/services/config.d.cts +0 -42
  137. package/dist/services/config.d.ts +0 -42
  138. package/dist/services/config.js +0 -17
  139. package/dist/services/connection.cjs +0 -17691
  140. package/dist/services/connection.d.cts +0 -95
  141. package/dist/services/connection.d.ts +0 -95
  142. package/dist/services/connection.js +0 -11
  143. package/dist/services/index.d.cts +0 -21
  144. package/dist/services/index.d.ts +0 -21
  145. package/dist/services/index.js +0 -58
  146. package/dist/services/lrc-connection.cjs +0 -4713
  147. package/dist/services/lrc-connection.d.cts +0 -34
  148. package/dist/services/lrc-connection.d.ts +0 -34
  149. package/dist/services/lrc-connection.js +0 -11
  150. package/dist/services/token-transactions.cjs +0 -2877
  151. package/dist/services/token-transactions.d.cts +0 -75
  152. package/dist/services/token-transactions.d.ts +0 -75
  153. package/dist/services/token-transactions.js +0 -15
  154. package/dist/services/wallet-config.cjs +0 -340
  155. package/dist/services/wallet-config.d.cts +0 -56
  156. package/dist/services/wallet-config.d.ts +0 -56
  157. package/dist/services/wallet-config.js +0 -33
  158. package/dist/signer/signer.cjs +0 -2004
  159. package/dist/signer/signer.d.cts +0 -10
  160. package/dist/signer/signer.d.ts +0 -10
  161. package/dist/signer/signer.js +0 -24
  162. package/dist/signer-BP6F__oR.d.cts +0 -187
  163. package/dist/signer-BVZJXcq7.d.ts +0 -187
  164. package/dist/utils/index.cjs +0 -2947
  165. package/dist/utils/index.d.cts +0 -18
  166. package/dist/utils/index.d.ts +0 -18
  167. package/dist/utils/index.js +0 -157
  168. package/ios/spark_frost.kt +0 -1900
  169. package/src/address/index.ts +0 -1
  170. package/src/services/lrc-connection.ts +0 -215
  171. /package/dist/{chunk-L3EHBOUX.js → chunk-BYXBJQAS.js} +0 -0
@@ -1,458 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/address/index.ts
21
- var address_exports = {};
22
- __export(address_exports, {
23
- decodeSparkAddress: () => decodeSparkAddress,
24
- encodeSparkAddress: () => encodeSparkAddress,
25
- isValidPublicKey: () => isValidPublicKey,
26
- isValidSparkAddress: () => isValidSparkAddress
27
- });
28
- module.exports = __toCommonJS(address_exports);
29
-
30
- // buffer.js
31
- var import_buffer = require("buffer");
32
- if (typeof globalThis.Buffer === "undefined") {
33
- globalThis.Buffer = import_buffer.Buffer;
34
- }
35
- if (typeof window !== "undefined") {
36
- if (typeof window.global === "undefined") {
37
- window.global = window;
38
- }
39
- if (typeof window.globalThis === "undefined") {
40
- window.globalThis = window;
41
- }
42
- }
43
-
44
- // src/address/address.ts
45
- var import_secp256k1 = require("@noble/curves/secp256k1");
46
- var import_utils2 = require("@noble/hashes/utils");
47
- var import_base2 = require("@scure/base");
48
-
49
- // src/proto/spark.ts
50
- var import_wire4 = require("@bufbuild/protobuf/wire");
51
-
52
- // src/proto/common.ts
53
- var import_wire = require("@bufbuild/protobuf/wire");
54
-
55
- // src/proto/google/protobuf/empty.ts
56
- var import_wire2 = require("@bufbuild/protobuf/wire");
57
-
58
- // src/proto/google/protobuf/timestamp.ts
59
- var import_wire3 = require("@bufbuild/protobuf/wire");
60
-
61
- // src/proto/spark.ts
62
- function createBaseSparkAddress() {
63
- return { identityPublicKey: new Uint8Array(0), paymentIntentFields: void 0 };
64
- }
65
- var SparkAddress = {
66
- encode(message, writer = new import_wire4.BinaryWriter()) {
67
- if (message.identityPublicKey.length !== 0) {
68
- writer.uint32(10).bytes(message.identityPublicKey);
69
- }
70
- if (message.paymentIntentFields !== void 0) {
71
- PaymentIntentFields.encode(message.paymentIntentFields, writer.uint32(18).fork()).join();
72
- }
73
- return writer;
74
- },
75
- decode(input, length) {
76
- const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
77
- const end = length === void 0 ? reader.len : reader.pos + length;
78
- const message = createBaseSparkAddress();
79
- while (reader.pos < end) {
80
- const tag = reader.uint32();
81
- switch (tag >>> 3) {
82
- case 1: {
83
- if (tag !== 10) {
84
- break;
85
- }
86
- message.identityPublicKey = reader.bytes();
87
- continue;
88
- }
89
- case 2: {
90
- if (tag !== 18) {
91
- break;
92
- }
93
- message.paymentIntentFields = PaymentIntentFields.decode(reader, reader.uint32());
94
- continue;
95
- }
96
- }
97
- if ((tag & 7) === 4 || tag === 0) {
98
- break;
99
- }
100
- reader.skip(tag & 7);
101
- }
102
- return message;
103
- },
104
- fromJSON(object) {
105
- return {
106
- identityPublicKey: isSet(object.identityPublicKey) ? bytesFromBase64(object.identityPublicKey) : new Uint8Array(0),
107
- paymentIntentFields: isSet(object.paymentIntentFields) ? PaymentIntentFields.fromJSON(object.paymentIntentFields) : void 0
108
- };
109
- },
110
- toJSON(message) {
111
- const obj = {};
112
- if (message.identityPublicKey.length !== 0) {
113
- obj.identityPublicKey = base64FromBytes(message.identityPublicKey);
114
- }
115
- if (message.paymentIntentFields !== void 0) {
116
- obj.paymentIntentFields = PaymentIntentFields.toJSON(message.paymentIntentFields);
117
- }
118
- return obj;
119
- },
120
- create(base) {
121
- return SparkAddress.fromPartial(base ?? {});
122
- },
123
- fromPartial(object) {
124
- const message = createBaseSparkAddress();
125
- message.identityPublicKey = object.identityPublicKey ?? new Uint8Array(0);
126
- message.paymentIntentFields = object.paymentIntentFields !== void 0 && object.paymentIntentFields !== null ? PaymentIntentFields.fromPartial(object.paymentIntentFields) : void 0;
127
- return message;
128
- }
129
- };
130
- function createBasePaymentIntentFields() {
131
- return { id: new Uint8Array(0), assetIdentifier: void 0, assetAmount: new Uint8Array(0), memo: void 0 };
132
- }
133
- var PaymentIntentFields = {
134
- encode(message, writer = new import_wire4.BinaryWriter()) {
135
- if (message.id.length !== 0) {
136
- writer.uint32(10).bytes(message.id);
137
- }
138
- if (message.assetIdentifier !== void 0) {
139
- writer.uint32(18).bytes(message.assetIdentifier);
140
- }
141
- if (message.assetAmount.length !== 0) {
142
- writer.uint32(26).bytes(message.assetAmount);
143
- }
144
- if (message.memo !== void 0) {
145
- writer.uint32(34).string(message.memo);
146
- }
147
- return writer;
148
- },
149
- decode(input, length) {
150
- const reader = input instanceof import_wire4.BinaryReader ? input : new import_wire4.BinaryReader(input);
151
- const end = length === void 0 ? reader.len : reader.pos + length;
152
- const message = createBasePaymentIntentFields();
153
- while (reader.pos < end) {
154
- const tag = reader.uint32();
155
- switch (tag >>> 3) {
156
- case 1: {
157
- if (tag !== 10) {
158
- break;
159
- }
160
- message.id = reader.bytes();
161
- continue;
162
- }
163
- case 2: {
164
- if (tag !== 18) {
165
- break;
166
- }
167
- message.assetIdentifier = reader.bytes();
168
- continue;
169
- }
170
- case 3: {
171
- if (tag !== 26) {
172
- break;
173
- }
174
- message.assetAmount = reader.bytes();
175
- continue;
176
- }
177
- case 4: {
178
- if (tag !== 34) {
179
- break;
180
- }
181
- message.memo = reader.string();
182
- continue;
183
- }
184
- }
185
- if ((tag & 7) === 4 || tag === 0) {
186
- break;
187
- }
188
- reader.skip(tag & 7);
189
- }
190
- return message;
191
- },
192
- fromJSON(object) {
193
- return {
194
- id: isSet(object.id) ? bytesFromBase64(object.id) : new Uint8Array(0),
195
- assetIdentifier: isSet(object.assetIdentifier) ? bytesFromBase64(object.assetIdentifier) : void 0,
196
- assetAmount: isSet(object.assetAmount) ? bytesFromBase64(object.assetAmount) : new Uint8Array(0),
197
- memo: isSet(object.memo) ? globalThis.String(object.memo) : void 0
198
- };
199
- },
200
- toJSON(message) {
201
- const obj = {};
202
- if (message.id.length !== 0) {
203
- obj.id = base64FromBytes(message.id);
204
- }
205
- if (message.assetIdentifier !== void 0) {
206
- obj.assetIdentifier = base64FromBytes(message.assetIdentifier);
207
- }
208
- if (message.assetAmount.length !== 0) {
209
- obj.assetAmount = base64FromBytes(message.assetAmount);
210
- }
211
- if (message.memo !== void 0) {
212
- obj.memo = message.memo;
213
- }
214
- return obj;
215
- },
216
- create(base) {
217
- return PaymentIntentFields.fromPartial(base ?? {});
218
- },
219
- fromPartial(object) {
220
- const message = createBasePaymentIntentFields();
221
- message.id = object.id ?? new Uint8Array(0);
222
- message.assetIdentifier = object.assetIdentifier ?? void 0;
223
- message.assetAmount = object.assetAmount ?? new Uint8Array(0);
224
- message.memo = object.memo ?? void 0;
225
- return message;
226
- }
227
- };
228
- function bytesFromBase64(b64) {
229
- if (globalThis.Buffer) {
230
- return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
231
- } else {
232
- const bin = globalThis.atob(b64);
233
- const arr = new Uint8Array(bin.length);
234
- for (let i = 0; i < bin.length; ++i) {
235
- arr[i] = bin.charCodeAt(i);
236
- }
237
- return arr;
238
- }
239
- }
240
- function base64FromBytes(arr) {
241
- if (globalThis.Buffer) {
242
- return globalThis.Buffer.from(arr).toString("base64");
243
- } else {
244
- const bin = [];
245
- arr.forEach((byte) => {
246
- bin.push(globalThis.String.fromCharCode(byte));
247
- });
248
- return globalThis.btoa(bin.join(""));
249
- }
250
- }
251
- function isSet(value) {
252
- return value !== null && value !== void 0;
253
- }
254
-
255
- // src/errors/base.ts
256
- var import_utils = require("@noble/hashes/utils");
257
- var SparkSDKError = class extends Error {
258
- context;
259
- originalError;
260
- constructor(message, context = {}, originalError) {
261
- const msg = getMessage(message, context, originalError);
262
- super(msg);
263
- this.name = this.constructor.name;
264
- this.context = context;
265
- this.originalError = originalError;
266
- if (Error.captureStackTrace) {
267
- Error.captureStackTrace(this, this.constructor);
268
- }
269
- }
270
- toString() {
271
- return this.message;
272
- }
273
- toJSON() {
274
- return {
275
- name: this.name,
276
- message: this.message,
277
- context: this.context,
278
- originalError: this.originalError ? {
279
- name: this.originalError.name,
280
- message: this.originalError.message,
281
- stack: this.originalError.stack
282
- } : void 0,
283
- stack: this.stack
284
- };
285
- }
286
- };
287
- function getMessage(message, context = {}, originalError) {
288
- const contextStr = Object.entries(context).map(([key, value]) => `${key}: ${safeStringify(value)}`).join(", ");
289
- const originalErrorStr = originalError ? `
290
- Original Error: ${originalError.message}` : "";
291
- return `SparkSDKError: ${message}${contextStr ? `
292
- Context: ${contextStr}` : ""}${originalErrorStr}`;
293
- }
294
- function safeStringify(value) {
295
- const replacer = (_, v) => {
296
- if (typeof v === "bigint") {
297
- return v.toString();
298
- }
299
- if (v instanceof Uint8Array) {
300
- return formatUint8Array(v);
301
- }
302
- return v;
303
- };
304
- if (typeof value === "bigint") {
305
- return `"${value.toString()}"`;
306
- }
307
- if (value instanceof Uint8Array) {
308
- return `"${formatUint8Array(value)}"`;
309
- }
310
- try {
311
- const result = JSON.stringify(value, replacer);
312
- return result === void 0 ? String(value) : result;
313
- } catch {
314
- try {
315
- return String(value);
316
- } catch {
317
- return "[Unserializable]";
318
- }
319
- }
320
- }
321
- function formatUint8Array(arr) {
322
- return `Uint8Array(0x${(0, import_utils.bytesToHex)(arr)})`;
323
- }
324
-
325
- // src/errors/types.ts
326
- var ValidationError = class extends SparkSDKError {
327
- constructor(message, context = {}, originalError) {
328
- super(message, context, originalError);
329
- }
330
- };
331
-
332
- // src/address/address.ts
333
- var import_uuidv7 = require("uuidv7");
334
- var import_utils3 = require("@noble/curves/abstract/utils");
335
- var AddressNetwork = {
336
- MAINNET: "sp",
337
- TESTNET: "spt",
338
- REGTEST: "sprt",
339
- SIGNET: "sps",
340
- LOCAL: "spl"
341
- };
342
- function encodeSparkAddress(payload) {
343
- try {
344
- isValidPublicKey(payload.identityPublicKey);
345
- let paymentIntentFields;
346
- if (payload.paymentIntentFields) {
347
- paymentIntentFields = payload.paymentIntentFields;
348
- }
349
- const sparkAddressProto = SparkAddress.create({
350
- identityPublicKey: (0, import_utils2.hexToBytes)(payload.identityPublicKey),
351
- paymentIntentFields
352
- });
353
- const serializedPayload = SparkAddress.encode(sparkAddressProto).finish();
354
- const words = import_base2.bech32m.toWords(serializedPayload);
355
- return import_base2.bech32m.encode(
356
- AddressNetwork[payload.network],
357
- words,
358
- 500
359
- );
360
- } catch (error) {
361
- throw new ValidationError(
362
- "Failed to encode Spark address",
363
- {
364
- field: "publicKey",
365
- value: payload.identityPublicKey
366
- },
367
- error
368
- );
369
- }
370
- }
371
- function decodeSparkAddress(address, network) {
372
- try {
373
- const decoded = import_base2.bech32m.decode(address, 500);
374
- if (decoded.prefix !== AddressNetwork[network]) {
375
- throw new ValidationError("Invalid Spark address prefix", {
376
- field: "address",
377
- value: address,
378
- expected: `prefix='${AddressNetwork[network]}'`
379
- });
380
- }
381
- const payload = SparkAddress.decode(import_base2.bech32m.fromWords(decoded.words));
382
- const publicKey = (0, import_utils2.bytesToHex)(payload.identityPublicKey);
383
- isValidPublicKey(publicKey);
384
- const paymentIntentFields = payload.paymentIntentFields;
385
- return {
386
- identityPublicKey: publicKey,
387
- network,
388
- paymentIntentFields: paymentIntentFields && {
389
- id: import_uuidv7.UUID.ofInner(paymentIntentFields.id).toString(),
390
- assetIdentifier: paymentIntentFields.assetIdentifier ? (0, import_utils2.bytesToHex)(paymentIntentFields.assetIdentifier) : void 0,
391
- assetAmount: (0, import_utils3.bytesToNumberBE)(paymentIntentFields.assetAmount),
392
- memo: paymentIntentFields.memo
393
- }
394
- };
395
- } catch (error) {
396
- if (error instanceof ValidationError) {
397
- throw error;
398
- }
399
- throw new ValidationError(
400
- "Failed to decode Spark address",
401
- {
402
- field: "address",
403
- value: address
404
- },
405
- error
406
- );
407
- }
408
- }
409
- function isValidSparkAddress(address) {
410
- try {
411
- const network = Object.entries(AddressNetwork).find(
412
- ([_, prefix]) => address.startsWith(prefix)
413
- )?.[0];
414
- if (!network) {
415
- throw new ValidationError("Invalid Spark address network", {
416
- field: "network",
417
- value: address,
418
- expected: Object.values(AddressNetwork)
419
- });
420
- }
421
- decodeSparkAddress(address, network);
422
- return true;
423
- } catch (error) {
424
- if (error instanceof ValidationError) {
425
- throw error;
426
- }
427
- throw new ValidationError(
428
- "Invalid Spark address",
429
- {
430
- field: "address",
431
- value: address
432
- },
433
- error
434
- );
435
- }
436
- }
437
- function isValidPublicKey(publicKey) {
438
- try {
439
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex(publicKey);
440
- point.assertValidity();
441
- } catch (error) {
442
- throw new ValidationError(
443
- "Invalid public key",
444
- {
445
- field: "publicKey",
446
- value: publicKey
447
- },
448
- error
449
- );
450
- }
451
- }
452
- // Annotate the CommonJS export names for ESM import in node:
453
- 0 && (module.exports = {
454
- decodeSparkAddress,
455
- encodeSparkAddress,
456
- isValidPublicKey,
457
- isValidSparkAddress
458
- });
@@ -1,32 +0,0 @@
1
- import { P as PaymentIntentFields } from '../spark-DbzGfse6.cjs';
2
- import { a as NetworkType } from '../network-Css46DAz.cjs';
3
- import '@bufbuild/protobuf/wire';
4
- import 'nice-grpc-common';
5
- import '@buildonspark/lrc20-sdk';
6
- import '@scure/btc-signer';
7
- import 'bitcoinjs-lib';
8
- import '../BitcoinNetwork-TnABML0T.cjs';
9
-
10
- declare const AddressNetwork: Record<NetworkType, string>;
11
- type SparkAddressFormat = `${(typeof AddressNetwork)[keyof typeof AddressNetwork]}1${string}`;
12
- interface SparkAddressData {
13
- identityPublicKey: string;
14
- network: NetworkType;
15
- paymentIntentFields?: PaymentIntentFields;
16
- }
17
- interface DecodedSparkAddressData {
18
- identityPublicKey: string;
19
- network: NetworkType;
20
- paymentIntentFields?: {
21
- id: string;
22
- assetIdentifier?: string;
23
- assetAmount: bigint;
24
- memo?: string;
25
- };
26
- }
27
- declare function encodeSparkAddress(payload: SparkAddressData): SparkAddressFormat;
28
- declare function decodeSparkAddress(address: string, network: NetworkType): DecodedSparkAddressData;
29
- declare function isValidSparkAddress(address: string): boolean;
30
- declare function isValidPublicKey(publicKey: string): void;
31
-
32
- export { type DecodedSparkAddressData, type SparkAddressData, type SparkAddressFormat, decodeSparkAddress, encodeSparkAddress, isValidPublicKey, isValidSparkAddress };
@@ -1,32 +0,0 @@
1
- import { P as PaymentIntentFields } from '../spark-DbzGfse6.js';
2
- import { a as NetworkType } from '../network-hynb7iTZ.js';
3
- import '@bufbuild/protobuf/wire';
4
- import 'nice-grpc-common';
5
- import '@buildonspark/lrc20-sdk';
6
- import '@scure/btc-signer';
7
- import 'bitcoinjs-lib';
8
- import '../BitcoinNetwork-TnABML0T.js';
9
-
10
- declare const AddressNetwork: Record<NetworkType, string>;
11
- type SparkAddressFormat = `${(typeof AddressNetwork)[keyof typeof AddressNetwork]}1${string}`;
12
- interface SparkAddressData {
13
- identityPublicKey: string;
14
- network: NetworkType;
15
- paymentIntentFields?: PaymentIntentFields;
16
- }
17
- interface DecodedSparkAddressData {
18
- identityPublicKey: string;
19
- network: NetworkType;
20
- paymentIntentFields?: {
21
- id: string;
22
- assetIdentifier?: string;
23
- assetAmount: bigint;
24
- memo?: string;
25
- };
26
- }
27
- declare function encodeSparkAddress(payload: SparkAddressData): SparkAddressFormat;
28
- declare function decodeSparkAddress(address: string, network: NetworkType): DecodedSparkAddressData;
29
- declare function isValidSparkAddress(address: string): boolean;
30
- declare function isValidPublicKey(publicKey: string): void;
31
-
32
- export { type DecodedSparkAddressData, type SparkAddressData, type SparkAddressFormat, decodeSparkAddress, encodeSparkAddress, isValidPublicKey, isValidSparkAddress };
@@ -1,17 +0,0 @@
1
- import "../chunk-L3EHBOUX.js";
2
- import {
3
- decodeSparkAddress,
4
- encodeSparkAddress,
5
- isValidPublicKey,
6
- isValidSparkAddress
7
- } from "../chunk-KMUMFYFX.js";
8
- import "../chunk-VTUGIIWI.js";
9
- import "../chunk-GSI4OLXZ.js";
10
- import "../chunk-BGGEVUJK.js";
11
- import "../chunk-MVRQ5US7.js";
12
- export {
13
- decodeSparkAddress,
14
- encodeSparkAddress,
15
- isValidPublicKey,
16
- isValidSparkAddress
17
- };