@buildonspark/spark-sdk 0.1.45 → 0.1.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/{chunk-I54FARY2.js → chunk-EAP3U3CW.js} +14 -14
- package/dist/chunk-GWFQ7EBA.js +3773 -0
- package/dist/{chunk-J2IE4Z7Y.js → chunk-NNX4OK44.js} +3487 -934
- package/dist/{RequestLightningSendInput-Du0z7Om7.d.cts → client-CvpTRpcw.d.cts} +422 -212
- package/dist/{RequestLightningSendInput-DEPd_fPO.d.ts → client-D7KgLN44.d.ts} +422 -212
- package/dist/graphql/objects/index.d.cts +5 -9
- package/dist/graphql/objects/index.d.ts +5 -9
- package/dist/graphql/objects/index.js +1 -1
- package/dist/index.cjs +20461 -23377
- package/dist/index.d.cts +15 -769
- package/dist/index.d.ts +15 -769
- package/dist/index.js +81 -71
- package/dist/index.node.cjs +21994 -25018
- package/dist/index.node.d.cts +312 -34
- package/dist/index.node.d.ts +312 -34
- package/dist/index.node.js +82 -176
- package/dist/native/index.cjs +22847 -25841
- package/dist/native/index.d.cts +974 -1138
- package/dist/native/index.d.ts +974 -1138
- package/dist/native/index.js +10604 -13592
- package/dist/proto/lrc20.d.cts +2 -2
- package/dist/proto/lrc20.d.ts +2 -2
- package/dist/proto/lrc20.js +3098 -46
- package/dist/proto/spark.d.cts +1 -1
- package/dist/proto/spark.d.ts +1 -1
- package/dist/proto/spark_token.d.cts +1 -1
- package/dist/proto/spark_token.d.ts +1 -1
- package/dist/{sdk-types-Cc4l4kb1.d.ts → sdk-types-BGCeea0G.d.ts} +1 -1
- package/dist/{sdk-types-B0SwjolI.d.cts → sdk-types-XUeQMLFP.d.cts} +1 -1
- package/dist/{spark-dM7EYXYQ.d.cts → spark-BbUrbvZz.d.cts} +1 -1
- package/dist/{spark-dM7EYXYQ.d.ts → spark-BbUrbvZz.d.ts} +1 -1
- package/dist/spark-wallet-BAFPpPtY.d.cts +923 -0
- package/dist/spark-wallet-CJkQW8pK.d.ts +923 -0
- package/dist/spark_bindings/native/index.d.cts +1 -1
- package/dist/spark_bindings/native/index.d.ts +1 -1
- package/dist/spark_bindings/wasm/index.d.cts +1 -1
- package/dist/spark_bindings/wasm/index.d.ts +1 -1
- package/dist/{services/index.cjs → tests/test-utils.cjs} +2512 -4380
- package/dist/tests/test-utils.d.cts +79 -0
- package/dist/tests/test-utils.d.ts +79 -0
- package/dist/tests/test-utils.js +85 -0
- package/dist/types/index.d.cts +5 -9
- package/dist/types/index.d.ts +5 -9
- package/dist/types/index.js +5 -5
- package/dist/{types-C-Rp0Oo7.d.cts → types-BADxR3bm.d.cts} +1 -1
- package/dist/{types-C-Rp0Oo7.d.ts → types-BADxR3bm.d.ts} +1 -1
- package/package.json +7 -35
- package/src/graphql/client.ts +59 -20
- package/src/index.node.ts +28 -2
- package/src/index.ts +31 -1
- package/src/native/index.ts +16 -2
- package/src/services/config.ts +4 -6
- package/src/services/connection.ts +131 -64
- package/src/services/lightning.ts +1 -2
- package/src/services/token-transactions.ts +7 -7
- package/src/services/transfer.ts +1 -1
- package/src/services/tree-creation.ts +1 -1
- package/src/services/wallet-config.ts +18 -10
- package/src/signer/signer.react-native.ts +2 -5
- package/src/signer/signer.ts +138 -64
- package/src/signer/types.ts +52 -0
- package/src/spark-wallet/spark-wallet.ts +79 -36
- package/src/spark-wallet/types.ts +4 -4
- package/src/tests/integration/coop-exit.test.ts +2 -1
- package/src/tests/integration/lightning.test.ts +2 -2
- package/src/tests/integration/swap.test.ts +1 -1
- package/src/tests/integration/transfer.test.ts +5 -5
- package/src/tests/integration/tree-creation.test.ts +1 -1
- package/src/tests/integration/wallet.test.ts +1 -0
- package/src/tests/isHermeticTest.ts +3 -24
- package/src/tests/{test-util.ts → test-utils.ts} +3 -7
- package/src/tests/wrapWithOtelSpan.test.ts +1 -1
- package/src/{address → utils}/address.ts +1 -1
- package/src/utils/crypto.ts +19 -9
- package/src/utils/index.ts +2 -0
- package/src/utils/network.ts +17 -0
- package/src/utils/secret-sharing.ts +1 -2
- package/src/utils/signing.ts +1 -1
- package/src/utils/token-transactions.ts +3 -3
- package/src/utils/unilateral-exit.ts +32 -0
- package/src/utils/xchain-address.ts +1 -1
- package/dist/BitcoinNetwork-TnABML0T.d.cts +0 -18
- package/dist/BitcoinNetwork-TnABML0T.d.ts +0 -18
- package/dist/LightningSendFeeEstimateInput-BgOhEAI-.d.cts +0 -10
- package/dist/LightningSendFeeEstimateInput-BgOhEAI-.d.ts +0 -10
- package/dist/address/index.cjs +0 -458
- package/dist/address/index.d.cts +0 -32
- package/dist/address/index.d.ts +0 -32
- package/dist/address/index.js +0 -17
- package/dist/chunk-5FUB65LX.js +0 -838
- package/dist/chunk-6264CGDM.js +0 -113
- package/dist/chunk-7V6N75CC.js +0 -24
- package/dist/chunk-C2S227QR.js +0 -2336
- package/dist/chunk-GSI4OLXZ.js +0 -117
- package/dist/chunk-GZ5IPPJ2.js +0 -170
- package/dist/chunk-HWJWKEIU.js +0 -75
- package/dist/chunk-KMUMFYFX.js +0 -137
- package/dist/chunk-L3EHBOUX.js +0 -0
- package/dist/chunk-NSJF5F5O.js +0 -325
- package/dist/chunk-NTFKFRQ2.js +0 -3146
- package/dist/chunk-PQN3C2MF.js +0 -1122
- package/dist/chunk-QNNSEJ4P.js +0 -232
- package/dist/chunk-R5PXJZQS.js +0 -277
- package/dist/chunk-VTUGIIWI.js +0 -0
- package/dist/chunk-YUPMXTCJ.js +0 -622
- package/dist/chunk-Z5HIAYFT.js +0 -84
- package/dist/index-B2AwKW5J.d.cts +0 -214
- package/dist/index-CJDi1HWc.d.ts +0 -214
- package/dist/network-BTJl-Sul.d.ts +0 -46
- package/dist/network-CqgsdUF2.d.cts +0 -46
- package/dist/services/config.cjs +0 -2354
- package/dist/services/config.d.cts +0 -42
- package/dist/services/config.d.ts +0 -42
- package/dist/services/config.js +0 -17
- package/dist/services/connection.cjs +0 -17691
- package/dist/services/connection.d.cts +0 -95
- package/dist/services/connection.d.ts +0 -95
- package/dist/services/connection.js +0 -11
- package/dist/services/index.d.cts +0 -21
- package/dist/services/index.d.ts +0 -21
- package/dist/services/index.js +0 -58
- package/dist/services/lrc-connection.cjs +0 -4713
- package/dist/services/lrc-connection.d.cts +0 -34
- package/dist/services/lrc-connection.d.ts +0 -34
- package/dist/services/lrc-connection.js +0 -11
- package/dist/services/token-transactions.cjs +0 -2877
- package/dist/services/token-transactions.d.cts +0 -75
- package/dist/services/token-transactions.d.ts +0 -75
- package/dist/services/token-transactions.js +0 -15
- package/dist/services/wallet-config.cjs +0 -340
- package/dist/services/wallet-config.d.cts +0 -56
- package/dist/services/wallet-config.d.ts +0 -56
- package/dist/services/wallet-config.js +0 -33
- package/dist/signer/signer.cjs +0 -2004
- package/dist/signer/signer.d.cts +0 -10
- package/dist/signer/signer.d.ts +0 -10
- package/dist/signer/signer.js +0 -24
- package/dist/signer-BocS_J6B.d.ts +0 -187
- package/dist/signer-DKS0AJkw.d.cts +0 -187
- package/dist/utils/index.cjs +0 -2947
- package/dist/utils/index.d.cts +0 -18
- package/dist/utils/index.d.ts +0 -18
- package/dist/utils/index.js +0 -157
- package/src/address/index.ts +0 -1
- package/src/services/lrc-connection.ts +0 -215
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
interface LightningSendFeeEstimateInput {
|
|
2
|
-
encodedInvoice: string;
|
|
3
|
-
/**
|
|
4
|
-
* The amount you will pay for this invoice in sats. It should ONLY be set when the invoice amount is
|
|
5
|
-
* zero.
|
|
6
|
-
**/
|
|
7
|
-
amountSats?: number | undefined;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type { LightningSendFeeEstimateInput as L };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
interface LightningSendFeeEstimateInput {
|
|
2
|
-
encodedInvoice: string;
|
|
3
|
-
/**
|
|
4
|
-
* The amount you will pay for this invoice in sats. It should ONLY be set when the invoice amount is
|
|
5
|
-
* zero.
|
|
6
|
-
**/
|
|
7
|
-
amountSats?: number | undefined;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type { LightningSendFeeEstimateInput as L };
|
package/dist/address/index.cjs
DELETED
|
@@ -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
|
-
});
|
package/dist/address/index.d.cts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { P as PaymentIntentFields } from '../spark-dM7EYXYQ.cjs';
|
|
2
|
-
import { a as NetworkType } from '../network-CqgsdUF2.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 };
|
package/dist/address/index.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { P as PaymentIntentFields } from '../spark-dM7EYXYQ.js';
|
|
2
|
-
import { a as NetworkType } from '../network-BTJl-Sul.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 };
|
package/dist/address/index.js
DELETED
|
@@ -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
|
-
};
|