@secondlayer/stacks 0.0.1
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/README.md +92 -0
- package/dist/shared/stacks-02actsrx.cjs +17 -0
- package/dist/shared/stacks-02actsrx.cjs.map +10 -0
- package/dist/shared/stacks-1aqm7c2h.cjs +110 -0
- package/dist/shared/stacks-1aqm7c2h.cjs.map +11 -0
- package/dist/shared/stacks-24h5k94q.cjs +74 -0
- package/dist/shared/stacks-24h5k94q.cjs.map +11 -0
- package/dist/shared/stacks-2ar4prfz.cjs +328 -0
- package/dist/shared/stacks-2ar4prfz.cjs.map +11 -0
- package/dist/shared/stacks-4py5pm0r.cjs +237 -0
- package/dist/shared/stacks-4py5pm0r.cjs.map +10 -0
- package/dist/shared/stacks-5tprhns9.cjs +54 -0
- package/dist/shared/stacks-5tprhns9.cjs.map +11 -0
- package/dist/shared/stacks-61rvzkz1.cjs +132 -0
- package/dist/shared/stacks-61rvzkz1.cjs.map +17 -0
- package/dist/shared/stacks-709tra19.js +30 -0
- package/dist/shared/stacks-709tra19.js.map +10 -0
- package/dist/shared/stacks-74k8cxgb.cjs +567 -0
- package/dist/shared/stacks-74k8cxgb.cjs.map +13 -0
- package/dist/shared/stacks-8m9byk2j.js +7 -0
- package/dist/shared/stacks-8m9byk2j.js.map +9 -0
- package/dist/shared/stacks-8yykgdww.js +125 -0
- package/dist/shared/stacks-8yykgdww.js.map +11 -0
- package/dist/shared/stacks-9g0jhab3.cjs +40 -0
- package/dist/shared/stacks-9g0jhab3.cjs.map +10 -0
- package/dist/shared/stacks-an5k8n4t.cjs +291 -0
- package/dist/shared/stacks-an5k8n4t.cjs.map +23 -0
- package/dist/shared/stacks-b008c3w8.cjs +214 -0
- package/dist/shared/stacks-b008c3w8.cjs.map +11 -0
- package/dist/shared/stacks-bnvfmt7y.cjs +31 -0
- package/dist/shared/stacks-bnvfmt7y.cjs.map +9 -0
- package/dist/shared/stacks-bycy6t9k.js +22 -0
- package/dist/shared/stacks-bycy6t9k.js.map +10 -0
- package/dist/shared/stacks-d1fmkv3p.js +258 -0
- package/dist/shared/stacks-d1fmkv3p.js.map +13 -0
- package/dist/shared/stacks-dr5en54r.cjs +119 -0
- package/dist/shared/stacks-dr5en54r.cjs.map +10 -0
- package/dist/shared/stacks-dxhntr76.js +278 -0
- package/dist/shared/stacks-dxhntr76.js.map +10 -0
- package/dist/shared/stacks-evnzth1q.cjs +35 -0
- package/dist/shared/stacks-evnzth1q.cjs.map +10 -0
- package/dist/shared/stacks-f3tk2k5s.js +27 -0
- package/dist/shared/stacks-f3tk2k5s.js.map +9 -0
- package/dist/shared/stacks-f7wdrzs3.js +285 -0
- package/dist/shared/stacks-f7wdrzs3.js.map +11 -0
- package/dist/shared/stacks-fcaefc5b.cjs +16 -0
- package/dist/shared/stacks-fcaefc5b.cjs.map +10 -0
- package/dist/shared/stacks-g9mcjcqg.cjs +3 -0
- package/dist/shared/stacks-g9mcjcqg.cjs.map +9 -0
- package/dist/shared/stacks-gck1sq7h.cjs +28 -0
- package/dist/shared/stacks-gck1sq7h.cjs.map +10 -0
- package/dist/shared/stacks-gjvbq6w7.js +46 -0
- package/dist/shared/stacks-gjvbq6w7.js.map +10 -0
- package/dist/shared/stacks-j2cy7qtt.js +237 -0
- package/dist/shared/stacks-j2cy7qtt.js.map +11 -0
- package/dist/shared/stacks-k08tgzyp.cjs +232 -0
- package/dist/shared/stacks-k08tgzyp.cjs.map +13 -0
- package/dist/shared/stacks-k2p5tv6x.js +37 -0
- package/dist/shared/stacks-k2p5tv6x.js.map +10 -0
- package/dist/shared/stacks-k58k970n.js +234 -0
- package/dist/shared/stacks-k58k970n.js.map +10 -0
- package/dist/shared/stacks-n2g56wgg.js +338 -0
- package/dist/shared/stacks-n2g56wgg.js.map +23 -0
- package/dist/shared/stacks-nqytwfcc.js +243 -0
- package/dist/shared/stacks-nqytwfcc.js.map +11 -0
- package/dist/shared/stacks-qcae5852.js +19 -0
- package/dist/shared/stacks-qcae5852.js.map +10 -0
- package/dist/shared/stacks-qt8ehebn.js +76 -0
- package/dist/shared/stacks-qt8ehebn.js.map +11 -0
- package/dist/shared/stacks-qvg7c24g.cjs +232 -0
- package/dist/shared/stacks-qvg7c24g.cjs.map +10 -0
- package/dist/shared/stacks-r1t6g3c3.cjs +241 -0
- package/dist/shared/stacks-r1t6g3c3.cjs.map +11 -0
- package/dist/shared/stacks-tjxmrssa.js +282 -0
- package/dist/shared/stacks-tjxmrssa.js.map +11 -0
- package/dist/shared/stacks-v9jqcpd4.js +18 -0
- package/dist/shared/stacks-v9jqcpd4.js.map +10 -0
- package/dist/shared/stacks-vdfag81a.cjs +121 -0
- package/dist/shared/stacks-vdfag81a.cjs.map +10 -0
- package/dist/shared/stacks-vdfs3e5v.js +134 -0
- package/dist/shared/stacks-vdfs3e5v.js.map +10 -0
- package/dist/shared/stacks-y3dh7hv1.js +60 -0
- package/dist/shared/stacks-y3dh7hv1.js.map +11 -0
- package/dist/shared/stacks-ya3x01yd.cjs +16 -0
- package/dist/shared/stacks-ya3x01yd.cjs.map +10 -0
- package/dist/shared/stacks-yfgsm6ap.js +599 -0
- package/dist/shared/stacks-yfgsm6ap.js.map +13 -0
- package/dist/shared/stacks-yfveb68e.js +121 -0
- package/dist/shared/stacks-yfveb68e.js.map +10 -0
- package/dist/shared/stacks-zm0b3tgy.js +160 -0
- package/dist/shared/stacks-zm0b3tgy.js.map +17 -0
- package/dist/shared/stacks-zyv9qqme.cjs +249 -0
- package/dist/shared/stacks-zyv9qqme.cjs.map +11 -0
- package/dist/src/accounts/index.cjs +90 -0
- package/dist/src/accounts/index.cjs.map +12 -0
- package/dist/src/accounts/index.d.cts +47 -0
- package/dist/src/accounts/index.d.ts +47 -0
- package/dist/src/accounts/index.js +104 -0
- package/dist/src/accounts/index.js.map +12 -0
- package/dist/src/actions/index.cjs +36 -0
- package/dist/src/actions/index.cjs.map +9 -0
- package/dist/src/actions/index.d.cts +886 -0
- package/dist/src/actions/index.d.ts +886 -0
- package/dist/src/actions/index.js +81 -0
- package/dist/src/actions/index.js.map +9 -0
- package/dist/src/bns/index.cjs +590 -0
- package/dist/src/bns/index.cjs.map +15 -0
- package/dist/src/bns/index.d.cts +241 -0
- package/dist/src/bns/index.d.ts +241 -0
- package/dist/src/bns/index.js +611 -0
- package/dist/src/bns/index.js.map +15 -0
- package/dist/src/chains/index.cjs +13 -0
- package/dist/src/chains/index.cjs.map +9 -0
- package/dist/src/chains/index.d.cts +53 -0
- package/dist/src/chains/index.d.ts +53 -0
- package/dist/src/chains/index.js +18 -0
- package/dist/src/chains/index.js.map +9 -0
- package/dist/src/clarity/index.cjs +3 -0
- package/dist/src/clarity/index.cjs.map +9 -0
- package/dist/src/clarity/index.d.cts +821 -0
- package/dist/src/clarity/index.d.ts +821 -0
- package/dist/src/clarity/index.js +145 -0
- package/dist/src/clarity/index.js.map +9 -0
- package/dist/src/connect/index.cjs +480 -0
- package/dist/src/connect/index.cjs.map +19 -0
- package/dist/src/connect/index.d.cts +110 -0
- package/dist/src/connect/index.d.ts +110 -0
- package/dist/src/connect/index.js +448 -0
- package/dist/src/connect/index.js.map +19 -0
- package/dist/src/connect/walletconnect/index.cjs +1322 -0
- package/dist/src/connect/walletconnect/index.cjs.map +18 -0
- package/dist/src/connect/walletconnect/index.d.cts +132 -0
- package/dist/src/connect/walletconnect/index.d.ts +132 -0
- package/dist/src/connect/walletconnect/index.js +1290 -0
- package/dist/src/connect/walletconnect/index.js.map +18 -0
- package/dist/src/index.cjs +557 -0
- package/dist/src/index.cjs.map +21 -0
- package/dist/src/index.d.cts +847 -0
- package/dist/src/index.d.ts +847 -0
- package/dist/src/index.js +629 -0
- package/dist/src/index.js.map +21 -0
- package/dist/src/postconditions/index.cjs +3 -0
- package/dist/src/postconditions/index.cjs.map +9 -0
- package/dist/src/postconditions/index.d.cts +91 -0
- package/dist/src/postconditions/index.d.ts +91 -0
- package/dist/src/postconditions/index.js +12 -0
- package/dist/src/postconditions/index.js.map +9 -0
- package/dist/src/pox/index.cjs +860 -0
- package/dist/src/pox/index.cjs.map +15 -0
- package/dist/src/pox/index.d.cts +244 -0
- package/dist/src/pox/index.d.ts +244 -0
- package/dist/src/pox/index.js +877 -0
- package/dist/src/pox/index.js.map +15 -0
- package/dist/src/stackingdao/index.cjs +300 -0
- package/dist/src/stackingdao/index.cjs.map +13 -0
- package/dist/src/stackingdao/index.d.cts +179 -0
- package/dist/src/stackingdao/index.d.ts +179 -0
- package/dist/src/stackingdao/index.js +318 -0
- package/dist/src/stackingdao/index.js.map +13 -0
- package/dist/src/subscriptions/index.cjs +14 -0
- package/dist/src/subscriptions/index.cjs.map +9 -0
- package/dist/src/subscriptions/index.d.cts +250 -0
- package/dist/src/subscriptions/index.d.ts +250 -0
- package/dist/src/subscriptions/index.js +21 -0
- package/dist/src/subscriptions/index.js.map +9 -0
- package/dist/src/transactions/index.cjs +50 -0
- package/dist/src/transactions/index.cjs.map +9 -0
- package/dist/src/transactions/index.d.cts +412 -0
- package/dist/src/transactions/index.d.ts +412 -0
- package/dist/src/transactions/index.js +101 -0
- package/dist/src/transactions/index.js.map +9 -0
- package/dist/src/utils/index.cjs +168 -0
- package/dist/src/utils/index.cjs.map +11 -0
- package/dist/src/utils/index.d.cts +140 -0
- package/dist/src/utils/index.d.ts +140 -0
- package/dist/src/utils/index.js +222 -0
- package/dist/src/utils/index.js.map +11 -0
- package/package.json +105 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClarityConversionError,
|
|
3
|
+
cvToJSON,
|
|
4
|
+
cvToValue,
|
|
5
|
+
jsToClarity,
|
|
6
|
+
prepareArgs,
|
|
7
|
+
prettyPrint,
|
|
8
|
+
validateArgs,
|
|
9
|
+
validateArgsArray
|
|
10
|
+
} from "../../shared/stacks-tjxmrssa.js";
|
|
11
|
+
import {
|
|
12
|
+
SIP009_ABI,
|
|
13
|
+
SIP010_ABI,
|
|
14
|
+
SIP013_ABI,
|
|
15
|
+
sip009Abi,
|
|
16
|
+
sip010Abi,
|
|
17
|
+
sip013Abi
|
|
18
|
+
} from "../../shared/stacks-k58k970n.js";
|
|
19
|
+
import {
|
|
20
|
+
CONTRACT_NAME_REGEX,
|
|
21
|
+
clarityValueToJS,
|
|
22
|
+
isAbiBuffer,
|
|
23
|
+
isAbiList,
|
|
24
|
+
isAbiOptional,
|
|
25
|
+
isAbiResponse,
|
|
26
|
+
isAbiStringAscii,
|
|
27
|
+
isAbiStringUtf8,
|
|
28
|
+
isAbiTraitReference,
|
|
29
|
+
isAbiTuple,
|
|
30
|
+
isArray,
|
|
31
|
+
isBool,
|
|
32
|
+
isContractPrincipal,
|
|
33
|
+
isErrResponse,
|
|
34
|
+
isInt128,
|
|
35
|
+
isOkResponse,
|
|
36
|
+
isOptional,
|
|
37
|
+
isPrincipal,
|
|
38
|
+
isResponse,
|
|
39
|
+
isStandardPrincipal,
|
|
40
|
+
isString,
|
|
41
|
+
isTraitReference,
|
|
42
|
+
isUint128,
|
|
43
|
+
isUint8Array,
|
|
44
|
+
jsToClarityValue,
|
|
45
|
+
toCamelCase
|
|
46
|
+
} from "../../shared/stacks-d1fmkv3p.js";
|
|
47
|
+
import {
|
|
48
|
+
Cl,
|
|
49
|
+
boolCV,
|
|
50
|
+
bufferCV,
|
|
51
|
+
contractPrincipalCV,
|
|
52
|
+
deserializeCV,
|
|
53
|
+
deserializeCVBytes,
|
|
54
|
+
falseCV,
|
|
55
|
+
intCV,
|
|
56
|
+
listCV,
|
|
57
|
+
noneCV,
|
|
58
|
+
responseErrorCV,
|
|
59
|
+
responseOkCV,
|
|
60
|
+
someCV,
|
|
61
|
+
standardPrincipalCV,
|
|
62
|
+
stringAsciiCV,
|
|
63
|
+
stringUtf8CV,
|
|
64
|
+
trueCV,
|
|
65
|
+
tupleCV,
|
|
66
|
+
uintCV
|
|
67
|
+
} from "../../shared/stacks-j2cy7qtt.js";
|
|
68
|
+
import {
|
|
69
|
+
ClarityWireType,
|
|
70
|
+
clarityTypeFromByte,
|
|
71
|
+
serializeCV,
|
|
72
|
+
serializeCVBytes
|
|
73
|
+
} from "../../shared/stacks-8yykgdww.js";
|
|
74
|
+
import"../../shared/stacks-v9jqcpd4.js";
|
|
75
|
+
import"../../shared/stacks-gjvbq6w7.js";
|
|
76
|
+
import"../../shared/stacks-nqytwfcc.js";
|
|
77
|
+
import"../../shared/stacks-8m9byk2j.js";
|
|
78
|
+
export {
|
|
79
|
+
validateArgsArray,
|
|
80
|
+
validateArgs,
|
|
81
|
+
uintCV,
|
|
82
|
+
tupleCV,
|
|
83
|
+
trueCV,
|
|
84
|
+
toCamelCase,
|
|
85
|
+
stringUtf8CV,
|
|
86
|
+
stringAsciiCV,
|
|
87
|
+
standardPrincipalCV,
|
|
88
|
+
someCV,
|
|
89
|
+
sip013Abi,
|
|
90
|
+
sip010Abi,
|
|
91
|
+
sip009Abi,
|
|
92
|
+
serializeCVBytes,
|
|
93
|
+
serializeCV,
|
|
94
|
+
responseOkCV,
|
|
95
|
+
responseErrorCV,
|
|
96
|
+
prettyPrint,
|
|
97
|
+
prepareArgs,
|
|
98
|
+
noneCV,
|
|
99
|
+
listCV,
|
|
100
|
+
jsToClarityValue,
|
|
101
|
+
jsToClarity,
|
|
102
|
+
isUint8Array,
|
|
103
|
+
isUint128,
|
|
104
|
+
isTraitReference,
|
|
105
|
+
isString,
|
|
106
|
+
isStandardPrincipal,
|
|
107
|
+
isResponse,
|
|
108
|
+
isPrincipal,
|
|
109
|
+
isOptional,
|
|
110
|
+
isOkResponse,
|
|
111
|
+
isInt128,
|
|
112
|
+
isErrResponse,
|
|
113
|
+
isContractPrincipal,
|
|
114
|
+
isBool,
|
|
115
|
+
isArray,
|
|
116
|
+
isAbiTuple,
|
|
117
|
+
isAbiTraitReference,
|
|
118
|
+
isAbiStringUtf8,
|
|
119
|
+
isAbiStringAscii,
|
|
120
|
+
isAbiResponse,
|
|
121
|
+
isAbiOptional,
|
|
122
|
+
isAbiList,
|
|
123
|
+
isAbiBuffer,
|
|
124
|
+
intCV,
|
|
125
|
+
falseCV,
|
|
126
|
+
deserializeCVBytes,
|
|
127
|
+
deserializeCV,
|
|
128
|
+
cvToValue,
|
|
129
|
+
cvToJSON,
|
|
130
|
+
contractPrincipalCV,
|
|
131
|
+
clarityValueToJS,
|
|
132
|
+
clarityTypeFromByte,
|
|
133
|
+
bufferCV,
|
|
134
|
+
boolCV,
|
|
135
|
+
SIP013_ABI,
|
|
136
|
+
SIP010_ABI,
|
|
137
|
+
SIP009_ABI,
|
|
138
|
+
ClarityWireType,
|
|
139
|
+
ClarityConversionError,
|
|
140
|
+
Cl,
|
|
141
|
+
CONTRACT_NAME_REGEX
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
//# debugId=565CB95AB940D0B164756E2164756E21
|
|
145
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
+
var __toCommonJS = (from) => {
|
|
7
|
+
var entry = __moduleCache.get(from), desc;
|
|
8
|
+
if (entry)
|
|
9
|
+
return entry;
|
|
10
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
}));
|
|
16
|
+
__moduleCache.set(from, entry);
|
|
17
|
+
return entry;
|
|
18
|
+
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
set: (newValue) => all[name] = () => newValue
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/connect/index.ts
|
|
30
|
+
var exports_connect = {};
|
|
31
|
+
__export(exports_connect, {
|
|
32
|
+
setProvider: () => setProvider,
|
|
33
|
+
request: () => request,
|
|
34
|
+
isWalletInstalled: () => isWalletInstalled,
|
|
35
|
+
isConnected: () => isConnected,
|
|
36
|
+
getProvider: () => getProvider,
|
|
37
|
+
disconnect: () => disconnect,
|
|
38
|
+
connect: () => connect,
|
|
39
|
+
JsonRpcErrorCode: () => JsonRpcErrorCode,
|
|
40
|
+
JsonRpcError: () => JsonRpcError,
|
|
41
|
+
ConnectError: () => ConnectError
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(exports_connect);
|
|
44
|
+
|
|
45
|
+
// src/errors/base.ts
|
|
46
|
+
class BaseError extends Error {
|
|
47
|
+
name = "StacksError";
|
|
48
|
+
shortMessage;
|
|
49
|
+
details;
|
|
50
|
+
constructor(shortMessage, options) {
|
|
51
|
+
const message = [
|
|
52
|
+
shortMessage,
|
|
53
|
+
options?.details ? `
|
|
54
|
+
${options.details}` : ""
|
|
55
|
+
].join("");
|
|
56
|
+
super(message, { cause: options?.cause });
|
|
57
|
+
this.shortMessage = shortMessage;
|
|
58
|
+
this.details = options?.details;
|
|
59
|
+
}
|
|
60
|
+
toJSON() {
|
|
61
|
+
return {
|
|
62
|
+
name: this.name,
|
|
63
|
+
message: this.message,
|
|
64
|
+
shortMessage: this.shortMessage,
|
|
65
|
+
details: this.details,
|
|
66
|
+
cause: this.cause instanceof Error ? this.cause.message : undefined
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/connect/errors.ts
|
|
72
|
+
class ConnectError extends BaseError {
|
|
73
|
+
name = "ConnectError";
|
|
74
|
+
}
|
|
75
|
+
var JsonRpcErrorCode;
|
|
76
|
+
((JsonRpcErrorCode2) => {
|
|
77
|
+
JsonRpcErrorCode2[JsonRpcErrorCode2["ParseError"] = -32700] = "ParseError";
|
|
78
|
+
JsonRpcErrorCode2[JsonRpcErrorCode2["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
79
|
+
JsonRpcErrorCode2[JsonRpcErrorCode2["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
80
|
+
JsonRpcErrorCode2[JsonRpcErrorCode2["InvalidParams"] = -32602] = "InvalidParams";
|
|
81
|
+
JsonRpcErrorCode2[JsonRpcErrorCode2["InternalError"] = -32603] = "InternalError";
|
|
82
|
+
JsonRpcErrorCode2[JsonRpcErrorCode2["UserRejection"] = -31001] = "UserRejection";
|
|
83
|
+
})(JsonRpcErrorCode ||= {});
|
|
84
|
+
|
|
85
|
+
class JsonRpcError extends ConnectError {
|
|
86
|
+
name = "JsonRpcError";
|
|
87
|
+
code;
|
|
88
|
+
data;
|
|
89
|
+
constructor(message, code, options) {
|
|
90
|
+
const details = options?.data !== undefined ? typeof options.data === "string" ? options.data : JSON.stringify(options.data) : undefined;
|
|
91
|
+
super(message, { cause: options?.cause, details });
|
|
92
|
+
this.code = code;
|
|
93
|
+
this.data = options?.data;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/connect/provider.ts
|
|
98
|
+
var customProvider = null;
|
|
99
|
+
function setProvider(provider) {
|
|
100
|
+
customProvider = provider;
|
|
101
|
+
}
|
|
102
|
+
function getProvider() {
|
|
103
|
+
if (customProvider)
|
|
104
|
+
return customProvider;
|
|
105
|
+
if (typeof window === "undefined") {
|
|
106
|
+
throw new ConnectError("No Stacks wallet found");
|
|
107
|
+
}
|
|
108
|
+
const provider = window.StacksProvider ?? window.LeatherProvider ?? window.XverseProvider ?? window.HiroWalletProvider;
|
|
109
|
+
if (!provider)
|
|
110
|
+
throw new ConnectError("No Stacks wallet found");
|
|
111
|
+
return provider;
|
|
112
|
+
}
|
|
113
|
+
function isWalletInstalled() {
|
|
114
|
+
return typeof window !== "undefined" && !!(window.StacksProvider || window.LeatherProvider || window.XverseProvider || window.HiroWalletProvider);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/connect/storage.ts
|
|
118
|
+
var STORAGE_KEY = "@secondlayer/connect";
|
|
119
|
+
function toHex(str) {
|
|
120
|
+
return Array.from(new TextEncoder().encode(str)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
121
|
+
}
|
|
122
|
+
function fromHex(hex) {
|
|
123
|
+
const bytes = new Uint8Array(hex.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
|
|
124
|
+
return new TextDecoder().decode(bytes);
|
|
125
|
+
}
|
|
126
|
+
function getLocalStorage() {
|
|
127
|
+
return typeof localStorage !== "undefined" ? localStorage : undefined;
|
|
128
|
+
}
|
|
129
|
+
function getStorageData() {
|
|
130
|
+
try {
|
|
131
|
+
const raw = getLocalStorage()?.getItem(STORAGE_KEY);
|
|
132
|
+
if (!raw)
|
|
133
|
+
return null;
|
|
134
|
+
return JSON.parse(fromHex(raw));
|
|
135
|
+
} catch {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function setStorageData(data) {
|
|
140
|
+
const encoded = toHex(JSON.stringify(data));
|
|
141
|
+
getLocalStorage()?.setItem(STORAGE_KEY, encoded);
|
|
142
|
+
}
|
|
143
|
+
function clearStorage() {
|
|
144
|
+
getLocalStorage()?.removeItem(STORAGE_KEY);
|
|
145
|
+
}
|
|
146
|
+
function cacheAddresses(addresses) {
|
|
147
|
+
const stx = addresses.filter((a) => a.address.startsWith("SP") || a.address.startsWith("ST"));
|
|
148
|
+
const btc = addresses.filter((a) => !a.address.startsWith("SP") && !a.address.startsWith("ST"));
|
|
149
|
+
setStorageData({
|
|
150
|
+
addresses: { stx, btc },
|
|
151
|
+
version: "0.0.1",
|
|
152
|
+
updatedAt: Date.now()
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/utils/encoding.ts
|
|
157
|
+
var hexes = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
158
|
+
function bytesToHex(bytes) {
|
|
159
|
+
let hex = "";
|
|
160
|
+
for (const b of bytes) {
|
|
161
|
+
hex += hexes[b];
|
|
162
|
+
}
|
|
163
|
+
return hex;
|
|
164
|
+
}
|
|
165
|
+
function hexToBytes(hex) {
|
|
166
|
+
hex = without0x(hex);
|
|
167
|
+
if (hex.length % 2)
|
|
168
|
+
hex = `0${hex}`;
|
|
169
|
+
const array = new Uint8Array(hex.length / 2);
|
|
170
|
+
for (let i = 0;i < array.length; i++) {
|
|
171
|
+
const j = i * 2;
|
|
172
|
+
const byte = Number.parseInt(hex.slice(j, j + 2), 16);
|
|
173
|
+
if (Number.isNaN(byte) || byte < 0)
|
|
174
|
+
throw new Error("Invalid byte sequence");
|
|
175
|
+
array[i] = byte;
|
|
176
|
+
}
|
|
177
|
+
return array;
|
|
178
|
+
}
|
|
179
|
+
function without0x(value) {
|
|
180
|
+
return /^0x/i.test(value) ? value.slice(2) : value;
|
|
181
|
+
}
|
|
182
|
+
function utf8ToBytes(str) {
|
|
183
|
+
return new TextEncoder().encode(str);
|
|
184
|
+
}
|
|
185
|
+
function asciiToBytes(str) {
|
|
186
|
+
const bytes = new Uint8Array(str.length);
|
|
187
|
+
for (let i = 0;i < str.length; i++) {
|
|
188
|
+
bytes[i] = str.charCodeAt(i) & 255;
|
|
189
|
+
}
|
|
190
|
+
return bytes;
|
|
191
|
+
}
|
|
192
|
+
function concatBytes(...arrays) {
|
|
193
|
+
if (arrays.length === 1)
|
|
194
|
+
return arrays[0];
|
|
195
|
+
const length = arrays.reduce((a, arr) => a + arr.length, 0);
|
|
196
|
+
const result = new Uint8Array(length);
|
|
197
|
+
let pad = 0;
|
|
198
|
+
for (const arr of arrays) {
|
|
199
|
+
result.set(arr, pad);
|
|
200
|
+
pad += arr.length;
|
|
201
|
+
}
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
function intToBigInt(value) {
|
|
205
|
+
if (typeof value === "bigint")
|
|
206
|
+
return value;
|
|
207
|
+
if (typeof value === "string")
|
|
208
|
+
return BigInt(value);
|
|
209
|
+
if (typeof value === "number") {
|
|
210
|
+
if (!Number.isInteger(value))
|
|
211
|
+
throw new RangeError("Values of type 'number' must be an integer.");
|
|
212
|
+
if (value > Number.MAX_SAFE_INTEGER)
|
|
213
|
+
throw new RangeError(`Values of type 'number' must be <= ${Number.MAX_SAFE_INTEGER}. Use BigInt instead.`);
|
|
214
|
+
return BigInt(value);
|
|
215
|
+
}
|
|
216
|
+
if (value instanceof Uint8Array)
|
|
217
|
+
return BigInt(`0x${bytesToHex(value)}`);
|
|
218
|
+
throw new TypeError("Must be a number, bigint, string, or Uint8Array.");
|
|
219
|
+
}
|
|
220
|
+
function bigIntToBytes(value, length = 16) {
|
|
221
|
+
const hex = value.toString(16).padStart(length * 2, "0");
|
|
222
|
+
return hexToBytes(hex);
|
|
223
|
+
}
|
|
224
|
+
function intToHex(integer, byteLength = 8) {
|
|
225
|
+
const value = typeof integer === "bigint" ? integer : intToBigInt(integer);
|
|
226
|
+
return value.toString(16).padStart(byteLength * 2, "0");
|
|
227
|
+
}
|
|
228
|
+
function toTwos(value, width) {
|
|
229
|
+
const limit = BigInt(1) << width - BigInt(1);
|
|
230
|
+
if (value < -limit || value > limit - BigInt(1)) {
|
|
231
|
+
throw new Error(`Unable to represent integer in width: ${width}`);
|
|
232
|
+
}
|
|
233
|
+
if (value >= BigInt(0))
|
|
234
|
+
return value;
|
|
235
|
+
return value + (BigInt(1) << width);
|
|
236
|
+
}
|
|
237
|
+
function writeUInt32BE(value) {
|
|
238
|
+
const buf = new Uint8Array(4);
|
|
239
|
+
buf[0] = value >>> 24 & 255;
|
|
240
|
+
buf[1] = value >>> 16 & 255;
|
|
241
|
+
buf[2] = value >>> 8 & 255;
|
|
242
|
+
buf[3] = value & 255;
|
|
243
|
+
return buf;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// src/utils/c32.ts
|
|
247
|
+
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
248
|
+
var C32 = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
249
|
+
var HEX = "0123456789abcdef";
|
|
250
|
+
function c32normalize(input) {
|
|
251
|
+
return input.toUpperCase().replace(/O/g, "0").replace(/L|I/g, "1");
|
|
252
|
+
}
|
|
253
|
+
function c32decode(c32input) {
|
|
254
|
+
c32input = c32normalize(c32input);
|
|
255
|
+
if (!c32input.match(`^[${C32}]*$`))
|
|
256
|
+
throw new Error("Not a c32-encoded string");
|
|
257
|
+
const zeroPrefix = c32input.match(`^${C32[0]}*`);
|
|
258
|
+
const numLeadingZeroBytes = zeroPrefix ? zeroPrefix[0].length : 0;
|
|
259
|
+
const res = [];
|
|
260
|
+
let carry = 0;
|
|
261
|
+
let carryBits = 0;
|
|
262
|
+
for (let i = c32input.length - 1;i >= 0; i--) {
|
|
263
|
+
if (carryBits === 4) {
|
|
264
|
+
res.unshift(HEX[carry]);
|
|
265
|
+
carryBits = 0;
|
|
266
|
+
carry = 0;
|
|
267
|
+
}
|
|
268
|
+
const currentValue = (C32.indexOf(c32input[i]) << carryBits) + carry;
|
|
269
|
+
res.unshift(HEX[currentValue % 16]);
|
|
270
|
+
carryBits += 1;
|
|
271
|
+
carry = currentValue >> 4;
|
|
272
|
+
if (carry > 1 << carryBits)
|
|
273
|
+
throw new Error("Panic error in c32 decoding");
|
|
274
|
+
}
|
|
275
|
+
res.unshift(HEX[carry]);
|
|
276
|
+
if (res.length % 2 === 1)
|
|
277
|
+
res.unshift("0");
|
|
278
|
+
let hexLeadingZeros = 0;
|
|
279
|
+
while (hexLeadingZeros < res.length && res[hexLeadingZeros] === "0")
|
|
280
|
+
hexLeadingZeros++;
|
|
281
|
+
let hexStr = res.slice(hexLeadingZeros - hexLeadingZeros % 2).join("");
|
|
282
|
+
for (let i = 0;i < numLeadingZeroBytes; i++)
|
|
283
|
+
hexStr = `00${hexStr}`;
|
|
284
|
+
return hexStr;
|
|
285
|
+
}
|
|
286
|
+
function c32checksum(dataHex) {
|
|
287
|
+
return bytesToHex(import_sha2.sha256(import_sha2.sha256(hexToBytes(dataHex))).slice(0, 4));
|
|
288
|
+
}
|
|
289
|
+
function c32checkDecode(c32data) {
|
|
290
|
+
c32data = c32normalize(c32data);
|
|
291
|
+
const dataHex = c32decode(c32data.slice(1));
|
|
292
|
+
const version = C32.indexOf(c32data[0]);
|
|
293
|
+
const checksum = dataHex.slice(-8);
|
|
294
|
+
let versionHex = version.toString(16);
|
|
295
|
+
if (versionHex.length === 1)
|
|
296
|
+
versionHex = `0${versionHex}`;
|
|
297
|
+
if (c32checksum(`${versionHex}${dataHex.substring(0, dataHex.length - 8)}`) !== checksum) {
|
|
298
|
+
throw new Error("Invalid c32check string: checksum mismatch");
|
|
299
|
+
}
|
|
300
|
+
return [version, dataHex.substring(0, dataHex.length - 8)];
|
|
301
|
+
}
|
|
302
|
+
function c32addressDecode(c32addr) {
|
|
303
|
+
if (c32addr.length <= 5)
|
|
304
|
+
throw new Error("Invalid c32 address: invalid length");
|
|
305
|
+
if (c32addr[0] !== "S")
|
|
306
|
+
throw new Error('Invalid c32 address: must start with "S"');
|
|
307
|
+
return c32checkDecode(c32addr.slice(1));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// src/clarity/types.ts
|
|
311
|
+
var ClarityWireType = {
|
|
312
|
+
int: 0,
|
|
313
|
+
uint: 1,
|
|
314
|
+
buffer: 2,
|
|
315
|
+
true: 3,
|
|
316
|
+
false: 4,
|
|
317
|
+
address: 5,
|
|
318
|
+
contract: 6,
|
|
319
|
+
ok: 7,
|
|
320
|
+
err: 8,
|
|
321
|
+
none: 9,
|
|
322
|
+
some: 10,
|
|
323
|
+
list: 11,
|
|
324
|
+
tuple: 12,
|
|
325
|
+
ascii: 13,
|
|
326
|
+
utf8: 14
|
|
327
|
+
};
|
|
328
|
+
var wireTypeToClarity = Object.fromEntries(Object.entries(ClarityWireType).map(([k, v]) => [v, k]));
|
|
329
|
+
|
|
330
|
+
// src/clarity/serialize.ts
|
|
331
|
+
var CLARITY_INT_SIZE = 128n;
|
|
332
|
+
var CLARITY_INT_BYTE_SIZE = 16;
|
|
333
|
+
function typeIdByte(type) {
|
|
334
|
+
return ClarityWireType[type];
|
|
335
|
+
}
|
|
336
|
+
function withTypeId(type, bytes) {
|
|
337
|
+
return concatBytes(new Uint8Array([typeIdByte(type)]), bytes);
|
|
338
|
+
}
|
|
339
|
+
function serializeAddress(c32Address) {
|
|
340
|
+
const [version, hash160] = c32addressDecode(c32Address);
|
|
341
|
+
return concatBytes(new Uint8Array([version]), hexToBytes(hash160));
|
|
342
|
+
}
|
|
343
|
+
function serializeLPString(str, prefixBytes = 1) {
|
|
344
|
+
const content = utf8ToBytes(str);
|
|
345
|
+
const lengthPrefix = hexToBytes(intToHex(content.byteLength, prefixBytes));
|
|
346
|
+
return concatBytes(lengthPrefix, content);
|
|
347
|
+
}
|
|
348
|
+
function serializeCVBytes(value) {
|
|
349
|
+
switch (value.type) {
|
|
350
|
+
case "true":
|
|
351
|
+
case "false":
|
|
352
|
+
return new Uint8Array([typeIdByte(value.type)]);
|
|
353
|
+
case "int": {
|
|
354
|
+
const bytes = bigIntToBytes(toTwos(BigInt(value.value), CLARITY_INT_SIZE), CLARITY_INT_BYTE_SIZE);
|
|
355
|
+
return withTypeId(value.type, bytes);
|
|
356
|
+
}
|
|
357
|
+
case "uint": {
|
|
358
|
+
const bytes = bigIntToBytes(BigInt(value.value), CLARITY_INT_BYTE_SIZE);
|
|
359
|
+
return withTypeId(value.type, bytes);
|
|
360
|
+
}
|
|
361
|
+
case "buffer": {
|
|
362
|
+
const bufBytes = hexToBytes(value.value);
|
|
363
|
+
return withTypeId(value.type, concatBytes(writeUInt32BE(bufBytes.length), bufBytes));
|
|
364
|
+
}
|
|
365
|
+
case "none":
|
|
366
|
+
return new Uint8Array([typeIdByte(value.type)]);
|
|
367
|
+
case "some":
|
|
368
|
+
return withTypeId(value.type, serializeCVBytes(value.value));
|
|
369
|
+
case "ok":
|
|
370
|
+
case "err":
|
|
371
|
+
return withTypeId(value.type, serializeCVBytes(value.value));
|
|
372
|
+
case "address":
|
|
373
|
+
return withTypeId(value.type, serializeAddress(value.value));
|
|
374
|
+
case "contract": {
|
|
375
|
+
const [addr, name] = value.value.split(".");
|
|
376
|
+
if (!addr || !name)
|
|
377
|
+
throw new Error(`Invalid contract principal: ${value.value}`);
|
|
378
|
+
return withTypeId(value.type, concatBytes(serializeAddress(addr), serializeLPString(name)));
|
|
379
|
+
}
|
|
380
|
+
case "list": {
|
|
381
|
+
const parts = [writeUInt32BE(value.value.length)];
|
|
382
|
+
for (const item of value.value) {
|
|
383
|
+
parts.push(serializeCVBytes(item));
|
|
384
|
+
}
|
|
385
|
+
return withTypeId(value.type, concatBytes(...parts));
|
|
386
|
+
}
|
|
387
|
+
case "tuple": {
|
|
388
|
+
const keys = Object.keys(value.value).sort((a, b) => a.localeCompare(b));
|
|
389
|
+
const parts = [writeUInt32BE(keys.length)];
|
|
390
|
+
for (const key of keys) {
|
|
391
|
+
parts.push(serializeLPString(key));
|
|
392
|
+
parts.push(serializeCVBytes(value.value[key]));
|
|
393
|
+
}
|
|
394
|
+
return withTypeId(value.type, concatBytes(...parts));
|
|
395
|
+
}
|
|
396
|
+
case "ascii": {
|
|
397
|
+
const strBytes = asciiToBytes(value.value);
|
|
398
|
+
return withTypeId(value.type, concatBytes(writeUInt32BE(strBytes.length), strBytes));
|
|
399
|
+
}
|
|
400
|
+
case "utf8": {
|
|
401
|
+
const strBytes = utf8ToBytes(value.value);
|
|
402
|
+
return withTypeId(value.type, concatBytes(writeUInt32BE(strBytes.length), strBytes));
|
|
403
|
+
}
|
|
404
|
+
default:
|
|
405
|
+
throw new Error(`Cannot serialize unknown clarity type`);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// src/connect/request.ts
|
|
410
|
+
var POST_CONDITION_TYPES = new Set([
|
|
411
|
+
"stx-postcondition",
|
|
412
|
+
"ft-postcondition",
|
|
413
|
+
"nft-postcondition"
|
|
414
|
+
]);
|
|
415
|
+
function isClarityValue(obj) {
|
|
416
|
+
return typeof obj === "object" && obj !== null && "type" in obj && typeof obj.type === "string" && !POST_CONDITION_TYPES.has(obj.type);
|
|
417
|
+
}
|
|
418
|
+
function serializeParams(value) {
|
|
419
|
+
if (value === null || value === undefined)
|
|
420
|
+
return value;
|
|
421
|
+
if (typeof value === "bigint")
|
|
422
|
+
return value.toString();
|
|
423
|
+
if (Array.isArray(value))
|
|
424
|
+
return value.map(serializeParams);
|
|
425
|
+
if (typeof value === "object") {
|
|
426
|
+
if (value instanceof Uint8Array)
|
|
427
|
+
return value;
|
|
428
|
+
if (POST_CONDITION_TYPES.has(value.type))
|
|
429
|
+
return value;
|
|
430
|
+
if (isClarityValue(value)) {
|
|
431
|
+
return bytesToHex(serializeCVBytes(value));
|
|
432
|
+
}
|
|
433
|
+
const result = {};
|
|
434
|
+
for (const [k, v] of Object.entries(value)) {
|
|
435
|
+
result[k] = serializeParams(v);
|
|
436
|
+
}
|
|
437
|
+
return result;
|
|
438
|
+
}
|
|
439
|
+
return value;
|
|
440
|
+
}
|
|
441
|
+
var ADDRESS_METHODS = new Set(["getAddresses", "stx_getAddresses"]);
|
|
442
|
+
async function request(method, ...args) {
|
|
443
|
+
const provider = getProvider();
|
|
444
|
+
const params = args[0];
|
|
445
|
+
const serialized = params ? serializeParams(params) : undefined;
|
|
446
|
+
let result;
|
|
447
|
+
try {
|
|
448
|
+
result = await provider.request(method, serialized);
|
|
449
|
+
} catch (err) {
|
|
450
|
+
if (err?.code !== undefined) {
|
|
451
|
+
throw new JsonRpcError(err.message ?? String(err), err.code, {
|
|
452
|
+
data: err.data
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
throw new ConnectError(err?.message ?? "Wallet request failed", {
|
|
456
|
+
cause: err instanceof Error ? err : undefined
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
if (ADDRESS_METHODS.has(method) && result?.addresses) {
|
|
460
|
+
cacheAddresses(result.addresses);
|
|
461
|
+
}
|
|
462
|
+
return result;
|
|
463
|
+
}
|
|
464
|
+
// src/connect/actions.ts
|
|
465
|
+
async function connect() {
|
|
466
|
+
return request("getAddresses");
|
|
467
|
+
}
|
|
468
|
+
function disconnect() {
|
|
469
|
+
clearStorage();
|
|
470
|
+
try {
|
|
471
|
+
getProvider().disconnect?.();
|
|
472
|
+
} catch {}
|
|
473
|
+
}
|
|
474
|
+
function isConnected() {
|
|
475
|
+
const data = getStorageData();
|
|
476
|
+
return (data?.addresses?.stx?.length ?? 0) > 0;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
//# debugId=94114852344D7D1664756E2164756E21
|
|
480
|
+
//# sourceMappingURL=index.cjs.map
|