@cartridge/controller 0.5.1 → 0.5.2
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/.turbo/turbo-build$colon$deps.log +116 -115
- package/.turbo/turbo-build.log +120 -0
- package/.turbo/turbo-format.log +25 -0
- package/dist/account.d.ts +2 -1
- package/dist/account.js +19 -4
- package/dist/account.js.map +1 -1
- package/dist/constants.d.ts +2 -1
- package/dist/constants.js +2 -0
- package/dist/constants.js.map +1 -1
- package/dist/controller.d.ts +2 -1
- package/dist/controller.js +27 -184
- package/dist/controller.js.map +1 -1
- package/dist/iframe/base.d.ts +2 -1
- package/dist/iframe/base.js +3 -177
- package/dist/iframe/base.js.map +1 -1
- package/dist/iframe/index.d.ts +2 -1
- package/dist/iframe/index.js +8 -180
- package/dist/iframe/index.js.map +1 -1
- package/dist/iframe/keychain.d.ts +2 -1
- package/dist/iframe/keychain.js +3 -177
- package/dist/iframe/keychain.js.map +1 -1
- package/dist/iframe/profile.d.ts +2 -1
- package/dist/iframe/profile.js +8 -180
- package/dist/iframe/profile.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +166 -185
- package/dist/index.js.map +1 -1
- package/dist/lookup.d.ts +4 -0
- package/dist/lookup.js +56 -0
- package/dist/lookup.js.map +1 -0
- package/dist/provider.d.ts +2 -1
- package/dist/session/account.d.ts +2 -2
- package/dist/session/account.js +6 -170
- package/dist/session/account.js.map +1 -1
- package/dist/session/index.d.ts +2 -2
- package/dist/session/index.js +20 -183
- package/dist/session/index.js.map +1 -1
- package/dist/session/provider.d.ts +4 -3
- package/dist/session/provider.js +19 -14
- package/dist/session/provider.js.map +1 -1
- package/dist/telegram/provider.d.ts +7 -4
- package/dist/telegram/provider.js +19 -14
- package/dist/telegram/provider.js.map +1 -1
- package/dist/{types-ikHqoYmG.d.ts → types-1WsOoNO2.d.ts} +17 -37
- package/dist/types.d.ts +2 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +5 -5
- package/dist/utils.js +80 -14
- package/dist/utils.js.map +1 -1
- package/package.json +5 -3
- package/src/account.ts +2 -1
- package/src/constants.ts +1 -0
- package/src/controller.ts +1 -1
- package/src/iframe/base.ts +3 -9
- package/src/iframe/profile.ts +5 -3
- package/src/index.ts +3 -1
- package/src/lookup.ts +68 -0
- package/src/session/account.ts +0 -1
- package/src/session/index.ts +0 -2
- package/src/session/provider.ts +4 -4
- package/src/telegram/provider.ts +7 -7
- package/src/types.ts +23 -44
- package/src/utils.ts +100 -16
- package/dist/presets.d.ts +0 -8
- package/dist/presets.js +0 -170
- package/dist/presets.js.map +0 -1
- package/src/presets.ts +0 -167
package/dist/index.js
CHANGED
|
@@ -13,6 +13,104 @@ var ResponseCodes = /* @__PURE__ */ ((ResponseCodes2) => {
|
|
|
13
13
|
return ResponseCodes2;
|
|
14
14
|
})(ResponseCodes || {});
|
|
15
15
|
|
|
16
|
+
// src/utils.ts
|
|
17
|
+
import {
|
|
18
|
+
addAddressPadding,
|
|
19
|
+
CallData,
|
|
20
|
+
getChecksumAddress,
|
|
21
|
+
hash,
|
|
22
|
+
typedData,
|
|
23
|
+
TypedDataRevision
|
|
24
|
+
} from "starknet";
|
|
25
|
+
var ALLOWED_PROPERTIES = /* @__PURE__ */ new Set([
|
|
26
|
+
"contracts",
|
|
27
|
+
"messages",
|
|
28
|
+
"target",
|
|
29
|
+
"method",
|
|
30
|
+
"name",
|
|
31
|
+
"description",
|
|
32
|
+
"types",
|
|
33
|
+
"domain",
|
|
34
|
+
"primaryType"
|
|
35
|
+
]);
|
|
36
|
+
function validatePropertyName(prop) {
|
|
37
|
+
if (!ALLOWED_PROPERTIES.has(prop)) {
|
|
38
|
+
throw new Error(`Invalid property name: ${prop}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function safeObjectAccess(obj, prop) {
|
|
42
|
+
validatePropertyName(prop);
|
|
43
|
+
return obj[prop];
|
|
44
|
+
}
|
|
45
|
+
function toSessionPolicies(policies) {
|
|
46
|
+
return Array.isArray(policies) ? policies.reduce(
|
|
47
|
+
(prev, p) => {
|
|
48
|
+
if (safeObjectAccess(p, "target")) {
|
|
49
|
+
const target = getChecksumAddress(
|
|
50
|
+
safeObjectAccess(p, "target")
|
|
51
|
+
);
|
|
52
|
+
const entrypoint = safeObjectAccess(p, "method");
|
|
53
|
+
const contracts = safeObjectAccess(
|
|
54
|
+
prev,
|
|
55
|
+
"contracts"
|
|
56
|
+
);
|
|
57
|
+
const item = {
|
|
58
|
+
name: humanizeString(entrypoint),
|
|
59
|
+
entrypoint,
|
|
60
|
+
description: safeObjectAccess(p, "description")
|
|
61
|
+
};
|
|
62
|
+
if (target in contracts) {
|
|
63
|
+
const methods = toArray(contracts[target].methods);
|
|
64
|
+
contracts[target] = {
|
|
65
|
+
methods: [...methods, item]
|
|
66
|
+
};
|
|
67
|
+
} else {
|
|
68
|
+
contracts[target] = {
|
|
69
|
+
methods: [item]
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
const messages = safeObjectAccess(prev, "messages");
|
|
74
|
+
messages.push(p);
|
|
75
|
+
}
|
|
76
|
+
return prev;
|
|
77
|
+
},
|
|
78
|
+
{ contracts: {}, messages: [] }
|
|
79
|
+
) : policies;
|
|
80
|
+
}
|
|
81
|
+
function toWasmPolicies(policies) {
|
|
82
|
+
return [
|
|
83
|
+
...Object.entries(policies.contracts ?? {}).flatMap(
|
|
84
|
+
([target, { methods }]) => toArray(methods).map((m) => ({
|
|
85
|
+
target,
|
|
86
|
+
method: m.entrypoint
|
|
87
|
+
}))
|
|
88
|
+
),
|
|
89
|
+
...(policies.messages ?? []).map((p) => {
|
|
90
|
+
const domainHash = typedData.getStructHash(
|
|
91
|
+
p.types,
|
|
92
|
+
"StarknetDomain",
|
|
93
|
+
p.domain,
|
|
94
|
+
TypedDataRevision.ACTIVE
|
|
95
|
+
);
|
|
96
|
+
const typeHash = typedData.getTypeHash(
|
|
97
|
+
p.types,
|
|
98
|
+
p.primaryType,
|
|
99
|
+
TypedDataRevision.ACTIVE
|
|
100
|
+
);
|
|
101
|
+
return {
|
|
102
|
+
scope_hash: hash.computePoseidonHash(domainHash, typeHash)
|
|
103
|
+
};
|
|
104
|
+
})
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
function toArray(val) {
|
|
108
|
+
return Array.isArray(val) ? val : [val];
|
|
109
|
+
}
|
|
110
|
+
function humanizeString(str) {
|
|
111
|
+
return str.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/_/g, " ").toLowerCase().replace(/^\w/, (c) => c.toUpperCase());
|
|
112
|
+
}
|
|
113
|
+
|
|
16
114
|
// src/account.ts
|
|
17
115
|
var ControllerAccount = class extends WalletAccount {
|
|
18
116
|
constructor(provider, address, keychain, options, modal) {
|
|
@@ -35,7 +133,7 @@ var ControllerAccount = class extends WalletAccount {
|
|
|
35
133
|
* @returns response from addTransaction
|
|
36
134
|
*/
|
|
37
135
|
async execute(calls) {
|
|
38
|
-
calls =
|
|
136
|
+
calls = toArray(calls);
|
|
39
137
|
return new Promise(async (resolve, reject) => {
|
|
40
138
|
const sessionExecute = await this.keychain.execute(
|
|
41
139
|
calls,
|
|
@@ -76,15 +174,15 @@ var ControllerAccount = class extends WalletAccount {
|
|
|
76
174
|
* @returns the signature of the JSON object
|
|
77
175
|
* @throws {Error} if the JSON object is not a valid JSON
|
|
78
176
|
*/
|
|
79
|
-
async signMessage(
|
|
177
|
+
async signMessage(typedData2) {
|
|
80
178
|
return new Promise(async (resolve, reject) => {
|
|
81
|
-
const sessionSign = await this.keychain.signMessage(
|
|
179
|
+
const sessionSign = await this.keychain.signMessage(typedData2, "", true);
|
|
82
180
|
if (!("code" in sessionSign)) {
|
|
83
181
|
resolve(sessionSign);
|
|
84
182
|
return;
|
|
85
183
|
}
|
|
86
184
|
this.modal.open();
|
|
87
|
-
const manualSign = await this.keychain.signMessage(
|
|
185
|
+
const manualSign = await this.keychain.signMessage(typedData2, "", false);
|
|
88
186
|
if (!("code" in manualSign)) {
|
|
89
187
|
resolve(manualSign);
|
|
90
188
|
} else {
|
|
@@ -98,175 +196,6 @@ var account_default = ControllerAccount;
|
|
|
98
196
|
|
|
99
197
|
// src/iframe/base.ts
|
|
100
198
|
import { connectToChild } from "@cartridge/penpal";
|
|
101
|
-
|
|
102
|
-
// src/presets.ts
|
|
103
|
-
var defaultPresets = {
|
|
104
|
-
cartridge: {
|
|
105
|
-
id: "cartridge",
|
|
106
|
-
name: "Cartridge",
|
|
107
|
-
icon: "/whitelabel/cartridge/icon.svg",
|
|
108
|
-
cover: {
|
|
109
|
-
light: "/whitelabel/cartridge/cover-light.png",
|
|
110
|
-
dark: "/whitelabel/cartridge/cover-dark.png"
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
"force-prime": {
|
|
114
|
-
id: "force-prime",
|
|
115
|
-
name: "Force Prime",
|
|
116
|
-
icon: "/whitelabel/force-prime/icon.png",
|
|
117
|
-
cover: "/whitelabel/force-prime/cover.png",
|
|
118
|
-
colors: {
|
|
119
|
-
primary: "#E1CC89"
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
paved: {
|
|
123
|
-
id: "paved",
|
|
124
|
-
name: "Paved",
|
|
125
|
-
icon: "/whitelabel/paved/icon.svg",
|
|
126
|
-
cover: "/whitelabel/paved/cover.png",
|
|
127
|
-
colors: {
|
|
128
|
-
primary: "#B0CAF8"
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
eternum: {
|
|
132
|
-
id: "eternum",
|
|
133
|
-
name: "Eternum",
|
|
134
|
-
icon: "/whitelabel/eternum/icon.gif",
|
|
135
|
-
cover: "/whitelabel/eternum/cover.png",
|
|
136
|
-
colors: {
|
|
137
|
-
primary: "#CE9822"
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
pistols: {
|
|
141
|
-
id: "pistols",
|
|
142
|
-
name: "Pistols at Ten Blocks",
|
|
143
|
-
icon: "/whitelabel/pistols/icon.png",
|
|
144
|
-
cover: "/whitelabel/pistols/cover.png",
|
|
145
|
-
colors: {
|
|
146
|
-
primary: "#EF9758"
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
pixelaw: {
|
|
150
|
-
id: "pixelaw",
|
|
151
|
-
name: "Pixelaw",
|
|
152
|
-
icon: "/whitelabel/pixelaw/icon.svg",
|
|
153
|
-
cover: "/whitelabel/pixelaw/cover.png",
|
|
154
|
-
colors: {
|
|
155
|
-
primary: "#7C00B1",
|
|
156
|
-
primaryForeground: "white"
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
"dope-wars": {
|
|
160
|
-
id: "dope-wars",
|
|
161
|
-
name: "Dope Wars",
|
|
162
|
-
icon: "/whitelabel/dope-wars/icon.png",
|
|
163
|
-
cover: "/whitelabel/dope-wars/cover.png",
|
|
164
|
-
colors: {
|
|
165
|
-
primary: "#11ED83"
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
zkastle: {
|
|
169
|
-
id: "zkastle",
|
|
170
|
-
name: "zKastle",
|
|
171
|
-
icon: "/whitelabel/zkastle/icon.svg",
|
|
172
|
-
cover: "/whitelabel/zkastle/cover.png",
|
|
173
|
-
colors: {
|
|
174
|
-
primary: "#E50D2C"
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
"loot-survivor": {
|
|
178
|
-
id: "loot-survivor",
|
|
179
|
-
name: "Loot Survivor",
|
|
180
|
-
icon: "/whitelabel/loot-survivor/icon.png",
|
|
181
|
-
cover: "/whitelabel/loot-survivor/cover.png",
|
|
182
|
-
colors: {
|
|
183
|
-
primary: "#33FF33"
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
zktt: {
|
|
187
|
-
id: "zktt",
|
|
188
|
-
name: "zKTT",
|
|
189
|
-
icon: "/whitelabel/zktt/icon.png",
|
|
190
|
-
cover: "/whitelabel/zktt/cover.png",
|
|
191
|
-
colors: {
|
|
192
|
-
primary: "#FFFFFF"
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
"tale-weaver": {
|
|
196
|
-
id: "tale-weaver",
|
|
197
|
-
name: "Tale Weaver",
|
|
198
|
-
icon: "/whitelabel/tale-weaver/icon.png",
|
|
199
|
-
cover: "/whitelabel/tale-weaver/cover.png",
|
|
200
|
-
colors: {
|
|
201
|
-
primary: "#fce377"
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
"realm-of-ra": {
|
|
205
|
-
id: "realm-of-ra",
|
|
206
|
-
name: "Realm of Ra",
|
|
207
|
-
icon: "/whitelabel/realm-of-ra/icon.png",
|
|
208
|
-
cover: "/whitelabel/realm-of-ra/cover.png",
|
|
209
|
-
colors: {
|
|
210
|
-
primary: "#de9534"
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
"jokers-of-neon": {
|
|
214
|
-
id: "jokers-of-neon",
|
|
215
|
-
name: "Jokers of Neon",
|
|
216
|
-
icon: "/whitelabel/jokers-of-neon/icon.png",
|
|
217
|
-
cover: "/whitelabel/jokers-of-neon/cover.png",
|
|
218
|
-
colors: {
|
|
219
|
-
primary: "#A144B2"
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
flippyflop: {
|
|
223
|
-
id: "flippyflop",
|
|
224
|
-
name: "FlippyFlop",
|
|
225
|
-
icon: "/whitelabel/flippyflop/icon.png",
|
|
226
|
-
cover: "/whitelabel/flippyflop/cover.png",
|
|
227
|
-
colors: {
|
|
228
|
-
primary: "#F38332"
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
|
-
"savage-summit": {
|
|
232
|
-
id: "savage-summit",
|
|
233
|
-
name: "Savage Summit",
|
|
234
|
-
icon: "/whitelabel/savage-summit/icon.png",
|
|
235
|
-
cover: "/whitelabel/savage-summit/cover.png",
|
|
236
|
-
colors: {
|
|
237
|
-
primary: "#fbf7da"
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
"dark-shuffle": {
|
|
241
|
-
id: "dark-shuffle",
|
|
242
|
-
name: "Dark Shuffle",
|
|
243
|
-
icon: "/whitelabel/dark-shuffle/icon.svg",
|
|
244
|
-
cover: "/whitelabel/dark-shuffle/cover.png",
|
|
245
|
-
colors: {
|
|
246
|
-
primary: "#F59100"
|
|
247
|
-
}
|
|
248
|
-
},
|
|
249
|
-
"blob-arena": {
|
|
250
|
-
id: "blob-arena",
|
|
251
|
-
name: "Blob Arena",
|
|
252
|
-
icon: "/whitelabel/blob-arena/icon.png",
|
|
253
|
-
cover: "/whitelabel/blob-arena/cover.png",
|
|
254
|
-
colors: {
|
|
255
|
-
primary: "#980f06"
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
zkube: {
|
|
259
|
-
id: "zkube",
|
|
260
|
-
name: "zKube",
|
|
261
|
-
icon: "/whitelabel/zkube/icon.png",
|
|
262
|
-
cover: "/whitelabel/zkube/cover.png",
|
|
263
|
-
colors: {
|
|
264
|
-
primary: "#5bc3e6"
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
// src/iframe/base.ts
|
|
270
199
|
var IFrame = class {
|
|
271
200
|
constructor({
|
|
272
201
|
id,
|
|
@@ -280,14 +209,9 @@ var IFrame = class {
|
|
|
280
209
|
if (typeof document === "undefined") {
|
|
281
210
|
return;
|
|
282
211
|
}
|
|
283
|
-
|
|
284
|
-
"theme",
|
|
285
|
-
|
|
286
|
-
JSON.stringify(
|
|
287
|
-
defaultPresets[theme ?? "cartridge"] ?? defaultPresets.cartridge
|
|
288
|
-
)
|
|
289
|
-
)
|
|
290
|
-
);
|
|
212
|
+
if (theme) {
|
|
213
|
+
url.searchParams.set("theme", encodeURIComponent(theme));
|
|
214
|
+
}
|
|
291
215
|
if (colorMode) {
|
|
292
216
|
url.searchParams.set("colorMode", colorMode);
|
|
293
217
|
}
|
|
@@ -380,6 +304,7 @@ var IFrame = class {
|
|
|
380
304
|
// src/constants.ts
|
|
381
305
|
var KEYCHAIN_URL = "https://x.cartridge.gg";
|
|
382
306
|
var PROFILE_URL = "https://profile.cartridge.gg";
|
|
307
|
+
var API_URL = "https://api.cartridge.gg";
|
|
383
308
|
|
|
384
309
|
// src/iframe/keychain.ts
|
|
385
310
|
var KeychainIFrame = class extends IFrame {
|
|
@@ -412,9 +337,11 @@ var ProfileIFrame = class extends IFrame {
|
|
|
412
337
|
}) {
|
|
413
338
|
const _profileUrl = (profileUrl || PROFILE_URL).replace(/\/$/, "");
|
|
414
339
|
const _url = new URL(
|
|
415
|
-
slot ? namespace ? `${_profileUrl}/account/${username}/slot/${slot}?
|
|
416
|
-
|
|
417
|
-
)}` : `${_profileUrl}/account/${username}/slot/${slot}
|
|
340
|
+
slot ? namespace ? `${_profileUrl}/account/${username}/slot/${slot}?ps=${encodeURIComponent(
|
|
341
|
+
slot
|
|
342
|
+
)}&ns=${encodeURIComponent(namespace)}` : `${_profileUrl}/account/${username}/slot/${slot}?ps=${encodeURIComponent(
|
|
343
|
+
slot
|
|
344
|
+
)}` : `${_profileUrl}/account/${username}`
|
|
418
345
|
);
|
|
419
346
|
_url.searchParams.set("rpcUrl", encodeURIComponent(rpcUrl));
|
|
420
347
|
if (tokens?.erc20) {
|
|
@@ -783,10 +710,64 @@ var ControllerProvider = class extends BaseProvider {
|
|
|
783
710
|
});
|
|
784
711
|
}
|
|
785
712
|
};
|
|
713
|
+
|
|
714
|
+
// src/lookup.ts
|
|
715
|
+
import { num } from "starknet";
|
|
716
|
+
var cache = /* @__PURE__ */ new Map();
|
|
717
|
+
async function lookup(request) {
|
|
718
|
+
if (!request.addresses?.length && !request.usernames?.length) {
|
|
719
|
+
return { results: [] };
|
|
720
|
+
}
|
|
721
|
+
const response = await fetch(`${API_URL}/lookup`, {
|
|
722
|
+
method: "POST",
|
|
723
|
+
headers: {
|
|
724
|
+
"Content-Type": "application/json"
|
|
725
|
+
},
|
|
726
|
+
body: JSON.stringify(request)
|
|
727
|
+
});
|
|
728
|
+
if (!response.ok) {
|
|
729
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
730
|
+
}
|
|
731
|
+
return response.json();
|
|
732
|
+
}
|
|
733
|
+
async function lookupUsernames(usernames) {
|
|
734
|
+
const uncachedUsernames = usernames.filter((name) => !cache.has(name));
|
|
735
|
+
if (uncachedUsernames.length > 0) {
|
|
736
|
+
const response = await lookup({ usernames: uncachedUsernames });
|
|
737
|
+
response.results.forEach((result) => {
|
|
738
|
+
cache.set(result.username, result.addresses[0]);
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
return new Map(
|
|
742
|
+
usernames.map((name) => [name, cache.get(name)]).filter((entry) => entry[1] !== void 0)
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
async function lookupAddresses(addresses) {
|
|
746
|
+
addresses = addresses.map(num.toHex);
|
|
747
|
+
const uncachedAddresses = addresses.filter((addr) => !cache.has(addr));
|
|
748
|
+
if (uncachedAddresses.length > 0) {
|
|
749
|
+
const response = await lookup({
|
|
750
|
+
addresses: uncachedAddresses
|
|
751
|
+
});
|
|
752
|
+
response.results.forEach((result) => {
|
|
753
|
+
cache.set(result.addresses[0], result.username);
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
return new Map(
|
|
757
|
+
addresses.map((addr) => [addr, cache.get(addr)]).filter((entry) => entry[1] !== void 0)
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// src/index.ts
|
|
762
|
+
export * from "@cartridge/presets";
|
|
786
763
|
export {
|
|
787
764
|
NotReadyToConnect,
|
|
788
765
|
ResponseCodes,
|
|
789
766
|
ControllerProvider as default,
|
|
790
|
-
|
|
767
|
+
lookupAddresses,
|
|
768
|
+
lookupUsernames,
|
|
769
|
+
toArray,
|
|
770
|
+
toSessionPolicies,
|
|
771
|
+
toWasmPolicies
|
|
791
772
|
};
|
|
792
773
|
//# sourceMappingURL=index.js.map
|