@sats-connect/core 0.6.2 → 0.6.3-d7b17f6
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/dist/index.d.mts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +107 -106
- package/dist/index.mjs +107 -106
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -132,6 +132,13 @@ declare const signMultipleTransactions: (options: SignMultipleTransactionOptions
|
|
|
132
132
|
declare const accountChangeEventName = "accountChange";
|
|
133
133
|
declare const accountChangeSchema: v.ObjectSchema<{
|
|
134
134
|
readonly type: v.LiteralSchema<"accountChange", undefined>;
|
|
135
|
+
readonly addresses: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
136
|
+
readonly address: v.StringSchema<undefined>;
|
|
137
|
+
readonly publicKey: v.StringSchema<undefined>;
|
|
138
|
+
readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
|
|
139
|
+
readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
|
|
140
|
+
readonly walletType: v.PicklistSchema<readonly ["software", "ledger", "keystone"], undefined>;
|
|
141
|
+
}, undefined>, undefined>, never>;
|
|
135
142
|
}, undefined>;
|
|
136
143
|
type AccountChangeEvent = v.InferOutput<typeof accountChangeSchema>;
|
|
137
144
|
declare const networkChangeEventName = "networkChange";
|
|
@@ -152,6 +159,13 @@ declare const disconnectSchema: v.ObjectSchema<{
|
|
|
152
159
|
type DisconnectEvent = v.InferOutput<typeof disconnectSchema>;
|
|
153
160
|
declare const walletEventSchema: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
154
161
|
readonly type: v.LiteralSchema<"accountChange", undefined>;
|
|
162
|
+
readonly addresses: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
163
|
+
readonly address: v.StringSchema<undefined>;
|
|
164
|
+
readonly publicKey: v.StringSchema<undefined>;
|
|
165
|
+
readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
|
|
166
|
+
readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
|
|
167
|
+
readonly walletType: v.PicklistSchema<readonly ["software", "ledger", "keystone"], undefined>;
|
|
168
|
+
}, undefined>, undefined>, never>;
|
|
155
169
|
}, undefined>, v.ObjectSchema<{
|
|
156
170
|
readonly type: v.LiteralSchema<"networkChange", undefined>;
|
|
157
171
|
readonly bitcoin: v.ObjectSchema<{
|
package/dist/index.d.ts
CHANGED
|
@@ -132,6 +132,13 @@ declare const signMultipleTransactions: (options: SignMultipleTransactionOptions
|
|
|
132
132
|
declare const accountChangeEventName = "accountChange";
|
|
133
133
|
declare const accountChangeSchema: v.ObjectSchema<{
|
|
134
134
|
readonly type: v.LiteralSchema<"accountChange", undefined>;
|
|
135
|
+
readonly addresses: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
136
|
+
readonly address: v.StringSchema<undefined>;
|
|
137
|
+
readonly publicKey: v.StringSchema<undefined>;
|
|
138
|
+
readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
|
|
139
|
+
readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
|
|
140
|
+
readonly walletType: v.PicklistSchema<readonly ["software", "ledger", "keystone"], undefined>;
|
|
141
|
+
}, undefined>, undefined>, never>;
|
|
135
142
|
}, undefined>;
|
|
136
143
|
type AccountChangeEvent = v.InferOutput<typeof accountChangeSchema>;
|
|
137
144
|
declare const networkChangeEventName = "networkChange";
|
|
@@ -152,6 +159,13 @@ declare const disconnectSchema: v.ObjectSchema<{
|
|
|
152
159
|
type DisconnectEvent = v.InferOutput<typeof disconnectSchema>;
|
|
153
160
|
declare const walletEventSchema: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
154
161
|
readonly type: v.LiteralSchema<"accountChange", undefined>;
|
|
162
|
+
readonly addresses: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
|
|
163
|
+
readonly address: v.StringSchema<undefined>;
|
|
164
|
+
readonly publicKey: v.StringSchema<undefined>;
|
|
165
|
+
readonly purpose: v.EnumSchema<typeof AddressPurpose, undefined>;
|
|
166
|
+
readonly addressType: v.EnumSchema<typeof AddressType, undefined>;
|
|
167
|
+
readonly walletType: v.PicklistSchema<readonly ["software", "ledger", "keystone"], undefined>;
|
|
168
|
+
}, undefined>, undefined>, never>;
|
|
155
169
|
}, undefined>, v.ObjectSchema<{
|
|
156
170
|
readonly type: v.LiteralSchema<"networkChange", undefined>;
|
|
157
171
|
readonly bitcoin: v.ObjectSchema<{
|
package/dist/index.js
CHANGED
|
@@ -205,8 +205,53 @@ __export(src_exports, {
|
|
|
205
205
|
});
|
|
206
206
|
module.exports = __toCommonJS(src_exports);
|
|
207
207
|
|
|
208
|
-
// src/
|
|
208
|
+
// src/addresses/index.ts
|
|
209
|
+
var import_jsontokens = require("jsontokens");
|
|
210
|
+
|
|
211
|
+
// src/addresses/types.ts
|
|
209
212
|
var v = __toESM(require("valibot"));
|
|
213
|
+
var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
|
|
214
|
+
AddressPurpose2["Ordinals"] = "ordinals";
|
|
215
|
+
AddressPurpose2["Payment"] = "payment";
|
|
216
|
+
AddressPurpose2["Stacks"] = "stacks";
|
|
217
|
+
return AddressPurpose2;
|
|
218
|
+
})(AddressPurpose || {});
|
|
219
|
+
var AddressType = /* @__PURE__ */ ((AddressType3) => {
|
|
220
|
+
AddressType3["p2pkh"] = "p2pkh";
|
|
221
|
+
AddressType3["p2sh"] = "p2sh";
|
|
222
|
+
AddressType3["p2wpkh"] = "p2wpkh";
|
|
223
|
+
AddressType3["p2wsh"] = "p2wsh";
|
|
224
|
+
AddressType3["p2tr"] = "p2tr";
|
|
225
|
+
AddressType3["stacks"] = "stacks";
|
|
226
|
+
return AddressType3;
|
|
227
|
+
})(AddressType || {});
|
|
228
|
+
var addressSchema = v.object({
|
|
229
|
+
address: v.string(),
|
|
230
|
+
publicKey: v.string(),
|
|
231
|
+
purpose: v.enum(AddressPurpose),
|
|
232
|
+
addressType: v.enum(AddressType),
|
|
233
|
+
walletType: walletTypeSchema
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// src/addresses/index.ts
|
|
237
|
+
var getAddress = async (options) => {
|
|
238
|
+
const provider = await getProviderOrThrow(options.getProvider);
|
|
239
|
+
const { purposes } = options.payload;
|
|
240
|
+
if (!purposes) {
|
|
241
|
+
throw new Error("Address purposes are required");
|
|
242
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
const request2 = (0, import_jsontokens.createUnsecuredToken)(options.payload);
|
|
245
|
+
const response = await provider.connect(request2);
|
|
246
|
+
options.onFinish?.(response);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
console.error("[Connect] Error during address request", error);
|
|
249
|
+
options.onCancel?.();
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// src/types.ts
|
|
254
|
+
var v2 = __toESM(require("valibot"));
|
|
210
255
|
var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType2) => {
|
|
211
256
|
BitcoinNetworkType2["Mainnet"] = "Mainnet";
|
|
212
257
|
BitcoinNetworkType2["Testnet"] = "Testnet";
|
|
@@ -215,22 +260,22 @@ var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType2) => {
|
|
|
215
260
|
BitcoinNetworkType2["Regtest"] = "Regtest";
|
|
216
261
|
return BitcoinNetworkType2;
|
|
217
262
|
})(BitcoinNetworkType || {});
|
|
218
|
-
var RpcIdSchema =
|
|
219
|
-
var rpcRequestMessageSchema =
|
|
220
|
-
jsonrpc:
|
|
221
|
-
method:
|
|
222
|
-
params:
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
263
|
+
var RpcIdSchema = v2.optional(v2.union([v2.string(), v2.number(), v2.null()]));
|
|
264
|
+
var rpcRequestMessageSchema = v2.object({
|
|
265
|
+
jsonrpc: v2.literal("2.0"),
|
|
266
|
+
method: v2.string(),
|
|
267
|
+
params: v2.optional(
|
|
268
|
+
v2.union([
|
|
269
|
+
v2.array(v2.unknown()),
|
|
270
|
+
v2.looseObject({}),
|
|
226
271
|
// Note: This is to support current incorrect usage of RPC 2.0. Params need
|
|
227
272
|
// to be either an array or an object when provided. Changing this now would
|
|
228
273
|
// be a breaking change, so accepting null values for now. Tracking in
|
|
229
274
|
// https://linear.app/xverseapp/issue/ENG-4538.
|
|
230
|
-
|
|
275
|
+
v2.null()
|
|
231
276
|
])
|
|
232
277
|
),
|
|
233
|
-
id:
|
|
278
|
+
id: v2.unwrap(RpcIdSchema)
|
|
234
279
|
});
|
|
235
280
|
var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
|
|
236
281
|
RpcErrorCode2[RpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
|
|
@@ -243,42 +288,43 @@ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
|
|
|
243
288
|
RpcErrorCode2[RpcErrorCode2["ACCESS_DENIED"] = -32002] = "ACCESS_DENIED";
|
|
244
289
|
return RpcErrorCode2;
|
|
245
290
|
})(RpcErrorCode || {});
|
|
246
|
-
var rpcSuccessResponseMessageSchema =
|
|
247
|
-
jsonrpc:
|
|
248
|
-
result:
|
|
291
|
+
var rpcSuccessResponseMessageSchema = v2.object({
|
|
292
|
+
jsonrpc: v2.literal("2.0"),
|
|
293
|
+
result: v2.nonOptional(v2.unknown()),
|
|
249
294
|
id: RpcIdSchema
|
|
250
295
|
});
|
|
251
|
-
var rpcErrorResponseMessageSchema =
|
|
252
|
-
jsonrpc:
|
|
253
|
-
error:
|
|
296
|
+
var rpcErrorResponseMessageSchema = v2.object({
|
|
297
|
+
jsonrpc: v2.literal("2.0"),
|
|
298
|
+
error: v2.nonOptional(v2.unknown()),
|
|
254
299
|
id: RpcIdSchema
|
|
255
300
|
});
|
|
256
|
-
var rpcResponseMessageSchema =
|
|
301
|
+
var rpcResponseMessageSchema = v2.union([
|
|
257
302
|
rpcSuccessResponseMessageSchema,
|
|
258
303
|
rpcErrorResponseMessageSchema
|
|
259
304
|
]);
|
|
260
305
|
|
|
261
306
|
// src/provider/types.ts
|
|
262
|
-
var
|
|
307
|
+
var v3 = __toESM(require("valibot"));
|
|
263
308
|
var accountChangeEventName = "accountChange";
|
|
264
|
-
var accountChangeSchema =
|
|
265
|
-
type:
|
|
309
|
+
var accountChangeSchema = v3.object({
|
|
310
|
+
type: v3.literal(accountChangeEventName),
|
|
311
|
+
addresses: v3.optional(v3.array(addressSchema))
|
|
266
312
|
});
|
|
267
313
|
var networkChangeEventName = "networkChange";
|
|
268
|
-
var networkChangeSchema =
|
|
269
|
-
type:
|
|
270
|
-
bitcoin:
|
|
271
|
-
name:
|
|
314
|
+
var networkChangeSchema = v3.object({
|
|
315
|
+
type: v3.literal(networkChangeEventName),
|
|
316
|
+
bitcoin: v3.object({
|
|
317
|
+
name: v3.enum(BitcoinNetworkType)
|
|
272
318
|
}),
|
|
273
|
-
stacks:
|
|
274
|
-
name:
|
|
319
|
+
stacks: v3.object({
|
|
320
|
+
name: v3.string()
|
|
275
321
|
})
|
|
276
322
|
});
|
|
277
323
|
var disconnectEventName = "disconnect";
|
|
278
|
-
var disconnectSchema =
|
|
279
|
-
type:
|
|
324
|
+
var disconnectSchema = v3.object({
|
|
325
|
+
type: v3.literal(disconnectEventName)
|
|
280
326
|
});
|
|
281
|
-
var walletEventSchema =
|
|
327
|
+
var walletEventSchema = v3.variant("type", [
|
|
282
328
|
accountChangeSchema,
|
|
283
329
|
networkChangeSchema,
|
|
284
330
|
disconnectSchema
|
|
@@ -327,26 +373,26 @@ function getSupportedWallets() {
|
|
|
327
373
|
var v21 = __toESM(require("valibot"));
|
|
328
374
|
|
|
329
375
|
// src/request/types/stxMethods/callContract.ts
|
|
330
|
-
var
|
|
376
|
+
var v4 = __toESM(require("valibot"));
|
|
331
377
|
var stxCallContractMethodName = "stx_callContract";
|
|
332
|
-
var stxCallContractParamsSchema =
|
|
378
|
+
var stxCallContractParamsSchema = v4.object({
|
|
333
379
|
/**
|
|
334
380
|
* The contract principal.
|
|
335
381
|
*
|
|
336
382
|
* E.g. `"SPKE...GD5C.my-contract"`
|
|
337
383
|
*/
|
|
338
|
-
contract:
|
|
384
|
+
contract: v4.string(),
|
|
339
385
|
/**
|
|
340
386
|
* The name of the function to call.
|
|
341
387
|
*
|
|
342
388
|
* Note: spec changes ongoing,
|
|
343
389
|
* https://github.com/stacksgov/sips/pull/166#pullrequestreview-1914236999
|
|
344
390
|
*/
|
|
345
|
-
functionName:
|
|
391
|
+
functionName: v4.string(),
|
|
346
392
|
/**
|
|
347
393
|
* @deprecated in favor of `functionArgs` for @stacks/connect compatibility
|
|
348
394
|
*/
|
|
349
|
-
arguments:
|
|
395
|
+
arguments: v4.optional(v4.array(v4.string())),
|
|
350
396
|
/**
|
|
351
397
|
* The function's arguments. The arguments are expected to be hex-encoded
|
|
352
398
|
* strings of Clarity values.
|
|
@@ -361,76 +407,76 @@ var stxCallContractParamsSchema = v3.object({
|
|
|
361
407
|
* const hexArgs = functionArgs.map(cvToHex);
|
|
362
408
|
* ```
|
|
363
409
|
*/
|
|
364
|
-
functionArgs:
|
|
410
|
+
functionArgs: v4.optional(v4.array(v4.string())),
|
|
365
411
|
/**
|
|
366
412
|
* The post conditions to apply to the contract call.
|
|
367
413
|
*/
|
|
368
|
-
postConditions:
|
|
414
|
+
postConditions: v4.optional(v4.array(v4.string())),
|
|
369
415
|
/**
|
|
370
416
|
* The mode to apply to the post conditions.
|
|
371
417
|
*/
|
|
372
|
-
postConditionMode:
|
|
418
|
+
postConditionMode: v4.optional(v4.union([v4.literal("allow"), v4.literal("deny")]))
|
|
373
419
|
});
|
|
374
|
-
var stxCallContractResultSchema =
|
|
420
|
+
var stxCallContractResultSchema = v4.object({
|
|
375
421
|
/**
|
|
376
422
|
* The ID of the transaction.
|
|
377
423
|
*/
|
|
378
|
-
txid:
|
|
424
|
+
txid: v4.string(),
|
|
379
425
|
/**
|
|
380
426
|
* A Stacks transaction as a hex-encoded string.
|
|
381
427
|
*/
|
|
382
|
-
transaction:
|
|
428
|
+
transaction: v4.string()
|
|
383
429
|
});
|
|
384
|
-
var stxCallContractRequestMessageSchema =
|
|
430
|
+
var stxCallContractRequestMessageSchema = v4.object({
|
|
385
431
|
...rpcRequestMessageSchema.entries,
|
|
386
|
-
...
|
|
387
|
-
method:
|
|
432
|
+
...v4.object({
|
|
433
|
+
method: v4.literal(stxCallContractMethodName),
|
|
388
434
|
params: stxCallContractParamsSchema,
|
|
389
|
-
id:
|
|
435
|
+
id: v4.string()
|
|
390
436
|
}).entries
|
|
391
437
|
});
|
|
392
438
|
|
|
393
439
|
// src/request/types/stxMethods/deployContract.ts
|
|
394
|
-
var
|
|
440
|
+
var v5 = __toESM(require("valibot"));
|
|
395
441
|
var stxDeployContractMethodName = "stx_deployContract";
|
|
396
|
-
var stxDeployContractParamsSchema =
|
|
442
|
+
var stxDeployContractParamsSchema = v5.object({
|
|
397
443
|
/**
|
|
398
444
|
* Name of the contract.
|
|
399
445
|
*/
|
|
400
|
-
name:
|
|
446
|
+
name: v5.string(),
|
|
401
447
|
/**
|
|
402
448
|
* The source code of the Clarity contract.
|
|
403
449
|
*/
|
|
404
|
-
clarityCode:
|
|
450
|
+
clarityCode: v5.string(),
|
|
405
451
|
/**
|
|
406
452
|
* The version of the Clarity contract.
|
|
407
453
|
*/
|
|
408
|
-
clarityVersion:
|
|
454
|
+
clarityVersion: v5.optional(v5.string()),
|
|
409
455
|
/**
|
|
410
456
|
* The post conditions to apply to the contract call.
|
|
411
457
|
*/
|
|
412
|
-
postConditions:
|
|
458
|
+
postConditions: v5.optional(v5.array(v5.string())),
|
|
413
459
|
/**
|
|
414
460
|
* The mode to apply to the post conditions.
|
|
415
461
|
*/
|
|
416
|
-
postConditionMode:
|
|
462
|
+
postConditionMode: v5.optional(v5.union([v5.literal("allow"), v5.literal("deny")]))
|
|
417
463
|
});
|
|
418
|
-
var stxDeployContractResultSchema =
|
|
464
|
+
var stxDeployContractResultSchema = v5.object({
|
|
419
465
|
/**
|
|
420
466
|
* The ID of the transaction.
|
|
421
467
|
*/
|
|
422
|
-
txid:
|
|
468
|
+
txid: v5.string(),
|
|
423
469
|
/**
|
|
424
470
|
* A Stacks transaction as a hex-encoded string.
|
|
425
471
|
*/
|
|
426
|
-
transaction:
|
|
472
|
+
transaction: v5.string()
|
|
427
473
|
});
|
|
428
|
-
var stxDeployContractRequestMessageSchema =
|
|
474
|
+
var stxDeployContractRequestMessageSchema = v5.object({
|
|
429
475
|
...rpcRequestMessageSchema.entries,
|
|
430
|
-
...
|
|
431
|
-
method:
|
|
476
|
+
...v5.object({
|
|
477
|
+
method: v5.literal(stxDeployContractMethodName),
|
|
432
478
|
params: stxDeployContractParamsSchema,
|
|
433
|
-
id:
|
|
479
|
+
id: v5.string()
|
|
434
480
|
}).entries
|
|
435
481
|
});
|
|
436
482
|
|
|
@@ -441,54 +487,9 @@ var v8 = __toESM(require("valibot"));
|
|
|
441
487
|
var v7 = __toESM(require("valibot"));
|
|
442
488
|
|
|
443
489
|
// src/request/types/common.ts
|
|
444
|
-
var v5 = __toESM(require("valibot"));
|
|
445
|
-
var walletTypes = ["software", "ledger", "keystone"];
|
|
446
|
-
var walletTypeSchema = v5.picklist(walletTypes);
|
|
447
|
-
|
|
448
|
-
// src/addresses/index.ts
|
|
449
|
-
var import_jsontokens = require("jsontokens");
|
|
450
|
-
|
|
451
|
-
// src/addresses/types.ts
|
|
452
490
|
var v6 = __toESM(require("valibot"));
|
|
453
|
-
var
|
|
454
|
-
|
|
455
|
-
AddressPurpose2["Payment"] = "payment";
|
|
456
|
-
AddressPurpose2["Stacks"] = "stacks";
|
|
457
|
-
return AddressPurpose2;
|
|
458
|
-
})(AddressPurpose || {});
|
|
459
|
-
var AddressType = /* @__PURE__ */ ((AddressType3) => {
|
|
460
|
-
AddressType3["p2pkh"] = "p2pkh";
|
|
461
|
-
AddressType3["p2sh"] = "p2sh";
|
|
462
|
-
AddressType3["p2wpkh"] = "p2wpkh";
|
|
463
|
-
AddressType3["p2wsh"] = "p2wsh";
|
|
464
|
-
AddressType3["p2tr"] = "p2tr";
|
|
465
|
-
AddressType3["stacks"] = "stacks";
|
|
466
|
-
return AddressType3;
|
|
467
|
-
})(AddressType || {});
|
|
468
|
-
var addressSchema = v6.object({
|
|
469
|
-
address: v6.string(),
|
|
470
|
-
publicKey: v6.string(),
|
|
471
|
-
purpose: v6.enum(AddressPurpose),
|
|
472
|
-
addressType: v6.enum(AddressType),
|
|
473
|
-
walletType: walletTypeSchema
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
// src/addresses/index.ts
|
|
477
|
-
var getAddress = async (options) => {
|
|
478
|
-
const provider = await getProviderOrThrow(options.getProvider);
|
|
479
|
-
const { purposes } = options.payload;
|
|
480
|
-
if (!purposes) {
|
|
481
|
-
throw new Error("Address purposes are required");
|
|
482
|
-
}
|
|
483
|
-
try {
|
|
484
|
-
const request2 = (0, import_jsontokens.createUnsecuredToken)(options.payload);
|
|
485
|
-
const response = await provider.connect(request2);
|
|
486
|
-
options.onFinish?.(response);
|
|
487
|
-
} catch (error) {
|
|
488
|
-
console.error("[Connect] Error during address request", error);
|
|
489
|
-
options.onCancel?.();
|
|
490
|
-
}
|
|
491
|
-
};
|
|
491
|
+
var walletTypes = ["software", "ledger", "keystone"];
|
|
492
|
+
var walletTypeSchema = v6.picklist(walletTypes);
|
|
492
493
|
|
|
493
494
|
// src/request/types/walletMethods.ts
|
|
494
495
|
var accountActionsSchema = v7.object({
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/addresses/index.ts
|
|
2
|
+
import { createUnsecuredToken } from "jsontokens";
|
|
3
|
+
|
|
4
|
+
// src/addresses/types.ts
|
|
2
5
|
import * as v from "valibot";
|
|
6
|
+
var AddressPurpose = /* @__PURE__ */ ((AddressPurpose2) => {
|
|
7
|
+
AddressPurpose2["Ordinals"] = "ordinals";
|
|
8
|
+
AddressPurpose2["Payment"] = "payment";
|
|
9
|
+
AddressPurpose2["Stacks"] = "stacks";
|
|
10
|
+
return AddressPurpose2;
|
|
11
|
+
})(AddressPurpose || {});
|
|
12
|
+
var AddressType = /* @__PURE__ */ ((AddressType3) => {
|
|
13
|
+
AddressType3["p2pkh"] = "p2pkh";
|
|
14
|
+
AddressType3["p2sh"] = "p2sh";
|
|
15
|
+
AddressType3["p2wpkh"] = "p2wpkh";
|
|
16
|
+
AddressType3["p2wsh"] = "p2wsh";
|
|
17
|
+
AddressType3["p2tr"] = "p2tr";
|
|
18
|
+
AddressType3["stacks"] = "stacks";
|
|
19
|
+
return AddressType3;
|
|
20
|
+
})(AddressType || {});
|
|
21
|
+
var addressSchema = v.object({
|
|
22
|
+
address: v.string(),
|
|
23
|
+
publicKey: v.string(),
|
|
24
|
+
purpose: v.enum(AddressPurpose),
|
|
25
|
+
addressType: v.enum(AddressType),
|
|
26
|
+
walletType: walletTypeSchema
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// src/addresses/index.ts
|
|
30
|
+
var getAddress = async (options) => {
|
|
31
|
+
const provider = await getProviderOrThrow(options.getProvider);
|
|
32
|
+
const { purposes } = options.payload;
|
|
33
|
+
if (!purposes) {
|
|
34
|
+
throw new Error("Address purposes are required");
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const request2 = createUnsecuredToken(options.payload);
|
|
38
|
+
const response = await provider.connect(request2);
|
|
39
|
+
options.onFinish?.(response);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error("[Connect] Error during address request", error);
|
|
42
|
+
options.onCancel?.();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/types.ts
|
|
47
|
+
import * as v2 from "valibot";
|
|
3
48
|
var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType2) => {
|
|
4
49
|
BitcoinNetworkType2["Mainnet"] = "Mainnet";
|
|
5
50
|
BitcoinNetworkType2["Testnet"] = "Testnet";
|
|
@@ -8,22 +53,22 @@ var BitcoinNetworkType = /* @__PURE__ */ ((BitcoinNetworkType2) => {
|
|
|
8
53
|
BitcoinNetworkType2["Regtest"] = "Regtest";
|
|
9
54
|
return BitcoinNetworkType2;
|
|
10
55
|
})(BitcoinNetworkType || {});
|
|
11
|
-
var RpcIdSchema =
|
|
12
|
-
var rpcRequestMessageSchema =
|
|
13
|
-
jsonrpc:
|
|
14
|
-
method:
|
|
15
|
-
params:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
56
|
+
var RpcIdSchema = v2.optional(v2.union([v2.string(), v2.number(), v2.null()]));
|
|
57
|
+
var rpcRequestMessageSchema = v2.object({
|
|
58
|
+
jsonrpc: v2.literal("2.0"),
|
|
59
|
+
method: v2.string(),
|
|
60
|
+
params: v2.optional(
|
|
61
|
+
v2.union([
|
|
62
|
+
v2.array(v2.unknown()),
|
|
63
|
+
v2.looseObject({}),
|
|
19
64
|
// Note: This is to support current incorrect usage of RPC 2.0. Params need
|
|
20
65
|
// to be either an array or an object when provided. Changing this now would
|
|
21
66
|
// be a breaking change, so accepting null values for now. Tracking in
|
|
22
67
|
// https://linear.app/xverseapp/issue/ENG-4538.
|
|
23
|
-
|
|
68
|
+
v2.null()
|
|
24
69
|
])
|
|
25
70
|
),
|
|
26
|
-
id:
|
|
71
|
+
id: v2.unwrap(RpcIdSchema)
|
|
27
72
|
});
|
|
28
73
|
var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
|
|
29
74
|
RpcErrorCode2[RpcErrorCode2["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
|
|
@@ -36,42 +81,43 @@ var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
|
|
|
36
81
|
RpcErrorCode2[RpcErrorCode2["ACCESS_DENIED"] = -32002] = "ACCESS_DENIED";
|
|
37
82
|
return RpcErrorCode2;
|
|
38
83
|
})(RpcErrorCode || {});
|
|
39
|
-
var rpcSuccessResponseMessageSchema =
|
|
40
|
-
jsonrpc:
|
|
41
|
-
result:
|
|
84
|
+
var rpcSuccessResponseMessageSchema = v2.object({
|
|
85
|
+
jsonrpc: v2.literal("2.0"),
|
|
86
|
+
result: v2.nonOptional(v2.unknown()),
|
|
42
87
|
id: RpcIdSchema
|
|
43
88
|
});
|
|
44
|
-
var rpcErrorResponseMessageSchema =
|
|
45
|
-
jsonrpc:
|
|
46
|
-
error:
|
|
89
|
+
var rpcErrorResponseMessageSchema = v2.object({
|
|
90
|
+
jsonrpc: v2.literal("2.0"),
|
|
91
|
+
error: v2.nonOptional(v2.unknown()),
|
|
47
92
|
id: RpcIdSchema
|
|
48
93
|
});
|
|
49
|
-
var rpcResponseMessageSchema =
|
|
94
|
+
var rpcResponseMessageSchema = v2.union([
|
|
50
95
|
rpcSuccessResponseMessageSchema,
|
|
51
96
|
rpcErrorResponseMessageSchema
|
|
52
97
|
]);
|
|
53
98
|
|
|
54
99
|
// src/provider/types.ts
|
|
55
|
-
import * as
|
|
100
|
+
import * as v3 from "valibot";
|
|
56
101
|
var accountChangeEventName = "accountChange";
|
|
57
|
-
var accountChangeSchema =
|
|
58
|
-
type:
|
|
102
|
+
var accountChangeSchema = v3.object({
|
|
103
|
+
type: v3.literal(accountChangeEventName),
|
|
104
|
+
addresses: v3.optional(v3.array(addressSchema))
|
|
59
105
|
});
|
|
60
106
|
var networkChangeEventName = "networkChange";
|
|
61
|
-
var networkChangeSchema =
|
|
62
|
-
type:
|
|
63
|
-
bitcoin:
|
|
64
|
-
name:
|
|
107
|
+
var networkChangeSchema = v3.object({
|
|
108
|
+
type: v3.literal(networkChangeEventName),
|
|
109
|
+
bitcoin: v3.object({
|
|
110
|
+
name: v3.enum(BitcoinNetworkType)
|
|
65
111
|
}),
|
|
66
|
-
stacks:
|
|
67
|
-
name:
|
|
112
|
+
stacks: v3.object({
|
|
113
|
+
name: v3.string()
|
|
68
114
|
})
|
|
69
115
|
});
|
|
70
116
|
var disconnectEventName = "disconnect";
|
|
71
|
-
var disconnectSchema =
|
|
72
|
-
type:
|
|
117
|
+
var disconnectSchema = v3.object({
|
|
118
|
+
type: v3.literal(disconnectEventName)
|
|
73
119
|
});
|
|
74
|
-
var walletEventSchema =
|
|
120
|
+
var walletEventSchema = v3.variant("type", [
|
|
75
121
|
accountChangeSchema,
|
|
76
122
|
networkChangeSchema,
|
|
77
123
|
disconnectSchema
|
|
@@ -120,26 +166,26 @@ function getSupportedWallets() {
|
|
|
120
166
|
import * as v21 from "valibot";
|
|
121
167
|
|
|
122
168
|
// src/request/types/stxMethods/callContract.ts
|
|
123
|
-
import * as
|
|
169
|
+
import * as v4 from "valibot";
|
|
124
170
|
var stxCallContractMethodName = "stx_callContract";
|
|
125
|
-
var stxCallContractParamsSchema =
|
|
171
|
+
var stxCallContractParamsSchema = v4.object({
|
|
126
172
|
/**
|
|
127
173
|
* The contract principal.
|
|
128
174
|
*
|
|
129
175
|
* E.g. `"SPKE...GD5C.my-contract"`
|
|
130
176
|
*/
|
|
131
|
-
contract:
|
|
177
|
+
contract: v4.string(),
|
|
132
178
|
/**
|
|
133
179
|
* The name of the function to call.
|
|
134
180
|
*
|
|
135
181
|
* Note: spec changes ongoing,
|
|
136
182
|
* https://github.com/stacksgov/sips/pull/166#pullrequestreview-1914236999
|
|
137
183
|
*/
|
|
138
|
-
functionName:
|
|
184
|
+
functionName: v4.string(),
|
|
139
185
|
/**
|
|
140
186
|
* @deprecated in favor of `functionArgs` for @stacks/connect compatibility
|
|
141
187
|
*/
|
|
142
|
-
arguments:
|
|
188
|
+
arguments: v4.optional(v4.array(v4.string())),
|
|
143
189
|
/**
|
|
144
190
|
* The function's arguments. The arguments are expected to be hex-encoded
|
|
145
191
|
* strings of Clarity values.
|
|
@@ -154,76 +200,76 @@ var stxCallContractParamsSchema = v3.object({
|
|
|
154
200
|
* const hexArgs = functionArgs.map(cvToHex);
|
|
155
201
|
* ```
|
|
156
202
|
*/
|
|
157
|
-
functionArgs:
|
|
203
|
+
functionArgs: v4.optional(v4.array(v4.string())),
|
|
158
204
|
/**
|
|
159
205
|
* The post conditions to apply to the contract call.
|
|
160
206
|
*/
|
|
161
|
-
postConditions:
|
|
207
|
+
postConditions: v4.optional(v4.array(v4.string())),
|
|
162
208
|
/**
|
|
163
209
|
* The mode to apply to the post conditions.
|
|
164
210
|
*/
|
|
165
|
-
postConditionMode:
|
|
211
|
+
postConditionMode: v4.optional(v4.union([v4.literal("allow"), v4.literal("deny")]))
|
|
166
212
|
});
|
|
167
|
-
var stxCallContractResultSchema =
|
|
213
|
+
var stxCallContractResultSchema = v4.object({
|
|
168
214
|
/**
|
|
169
215
|
* The ID of the transaction.
|
|
170
216
|
*/
|
|
171
|
-
txid:
|
|
217
|
+
txid: v4.string(),
|
|
172
218
|
/**
|
|
173
219
|
* A Stacks transaction as a hex-encoded string.
|
|
174
220
|
*/
|
|
175
|
-
transaction:
|
|
221
|
+
transaction: v4.string()
|
|
176
222
|
});
|
|
177
|
-
var stxCallContractRequestMessageSchema =
|
|
223
|
+
var stxCallContractRequestMessageSchema = v4.object({
|
|
178
224
|
...rpcRequestMessageSchema.entries,
|
|
179
|
-
...
|
|
180
|
-
method:
|
|
225
|
+
...v4.object({
|
|
226
|
+
method: v4.literal(stxCallContractMethodName),
|
|
181
227
|
params: stxCallContractParamsSchema,
|
|
182
|
-
id:
|
|
228
|
+
id: v4.string()
|
|
183
229
|
}).entries
|
|
184
230
|
});
|
|
185
231
|
|
|
186
232
|
// src/request/types/stxMethods/deployContract.ts
|
|
187
|
-
import * as
|
|
233
|
+
import * as v5 from "valibot";
|
|
188
234
|
var stxDeployContractMethodName = "stx_deployContract";
|
|
189
|
-
var stxDeployContractParamsSchema =
|
|
235
|
+
var stxDeployContractParamsSchema = v5.object({
|
|
190
236
|
/**
|
|
191
237
|
* Name of the contract.
|
|
192
238
|
*/
|
|
193
|
-
name:
|
|
239
|
+
name: v5.string(),
|
|
194
240
|
/**
|
|
195
241
|
* The source code of the Clarity contract.
|
|
196
242
|
*/
|
|
197
|
-
clarityCode:
|
|
243
|
+
clarityCode: v5.string(),
|
|
198
244
|
/**
|
|
199
245
|
* The version of the Clarity contract.
|
|
200
246
|
*/
|
|
201
|
-
clarityVersion:
|
|
247
|
+
clarityVersion: v5.optional(v5.string()),
|
|
202
248
|
/**
|
|
203
249
|
* The post conditions to apply to the contract call.
|
|
204
250
|
*/
|
|
205
|
-
postConditions:
|
|
251
|
+
postConditions: v5.optional(v5.array(v5.string())),
|
|
206
252
|
/**
|
|
207
253
|
* The mode to apply to the post conditions.
|
|
208
254
|
*/
|
|
209
|
-
postConditionMode:
|
|
255
|
+
postConditionMode: v5.optional(v5.union([v5.literal("allow"), v5.literal("deny")]))
|
|
210
256
|
});
|
|
211
|
-
var stxDeployContractResultSchema =
|
|
257
|
+
var stxDeployContractResultSchema = v5.object({
|
|
212
258
|
/**
|
|
213
259
|
* The ID of the transaction.
|
|
214
260
|
*/
|
|
215
|
-
txid:
|
|
261
|
+
txid: v5.string(),
|
|
216
262
|
/**
|
|
217
263
|
* A Stacks transaction as a hex-encoded string.
|
|
218
264
|
*/
|
|
219
|
-
transaction:
|
|
265
|
+
transaction: v5.string()
|
|
220
266
|
});
|
|
221
|
-
var stxDeployContractRequestMessageSchema =
|
|
267
|
+
var stxDeployContractRequestMessageSchema = v5.object({
|
|
222
268
|
...rpcRequestMessageSchema.entries,
|
|
223
|
-
...
|
|
224
|
-
method:
|
|
269
|
+
...v5.object({
|
|
270
|
+
method: v5.literal(stxDeployContractMethodName),
|
|
225
271
|
params: stxDeployContractParamsSchema,
|
|
226
|
-
id:
|
|
272
|
+
id: v5.string()
|
|
227
273
|
}).entries
|
|
228
274
|
});
|
|
229
275
|
|
|
@@ -234,54 +280,9 @@ import * as v8 from "valibot";
|
|
|
234
280
|
import * as v7 from "valibot";
|
|
235
281
|
|
|
236
282
|
// src/request/types/common.ts
|
|
237
|
-
import * as v5 from "valibot";
|
|
238
|
-
var walletTypes = ["software", "ledger", "keystone"];
|
|
239
|
-
var walletTypeSchema = v5.picklist(walletTypes);
|
|
240
|
-
|
|
241
|
-
// src/addresses/index.ts
|
|
242
|
-
import { createUnsecuredToken } from "jsontokens";
|
|
243
|
-
|
|
244
|
-
// src/addresses/types.ts
|
|
245
283
|
import * as v6 from "valibot";
|
|
246
|
-
var
|
|
247
|
-
|
|
248
|
-
AddressPurpose2["Payment"] = "payment";
|
|
249
|
-
AddressPurpose2["Stacks"] = "stacks";
|
|
250
|
-
return AddressPurpose2;
|
|
251
|
-
})(AddressPurpose || {});
|
|
252
|
-
var AddressType = /* @__PURE__ */ ((AddressType3) => {
|
|
253
|
-
AddressType3["p2pkh"] = "p2pkh";
|
|
254
|
-
AddressType3["p2sh"] = "p2sh";
|
|
255
|
-
AddressType3["p2wpkh"] = "p2wpkh";
|
|
256
|
-
AddressType3["p2wsh"] = "p2wsh";
|
|
257
|
-
AddressType3["p2tr"] = "p2tr";
|
|
258
|
-
AddressType3["stacks"] = "stacks";
|
|
259
|
-
return AddressType3;
|
|
260
|
-
})(AddressType || {});
|
|
261
|
-
var addressSchema = v6.object({
|
|
262
|
-
address: v6.string(),
|
|
263
|
-
publicKey: v6.string(),
|
|
264
|
-
purpose: v6.enum(AddressPurpose),
|
|
265
|
-
addressType: v6.enum(AddressType),
|
|
266
|
-
walletType: walletTypeSchema
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
// src/addresses/index.ts
|
|
270
|
-
var getAddress = async (options) => {
|
|
271
|
-
const provider = await getProviderOrThrow(options.getProvider);
|
|
272
|
-
const { purposes } = options.payload;
|
|
273
|
-
if (!purposes) {
|
|
274
|
-
throw new Error("Address purposes are required");
|
|
275
|
-
}
|
|
276
|
-
try {
|
|
277
|
-
const request2 = createUnsecuredToken(options.payload);
|
|
278
|
-
const response = await provider.connect(request2);
|
|
279
|
-
options.onFinish?.(response);
|
|
280
|
-
} catch (error) {
|
|
281
|
-
console.error("[Connect] Error during address request", error);
|
|
282
|
-
options.onCancel?.();
|
|
283
|
-
}
|
|
284
|
-
};
|
|
284
|
+
var walletTypes = ["software", "ledger", "keystone"];
|
|
285
|
+
var walletTypeSchema = v6.picklist(walletTypes);
|
|
285
286
|
|
|
286
287
|
// src/request/types/walletMethods.ts
|
|
287
288
|
var accountActionsSchema = v7.object({
|