@cartridge/controller 0.5.9 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build$colon$deps.log +53 -115
- package/.turbo/turbo-build.log +54 -116
- package/dist/controller.cjs +860 -0
- package/dist/controller.cjs.map +1 -0
- package/dist/controller.d.cts +33 -0
- package/dist/controller.d.ts +4 -4
- package/dist/controller.js +254 -170
- package/dist/controller.js.map +1 -1
- package/dist/index.cjs +2200 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +17 -0
- package/dist/index.d.ts +12 -6
- package/dist/index.js +296 -7666
- package/dist/index.js.map +1 -1
- package/dist/lookup.cjs +59 -0
- package/dist/lookup.cjs.map +1 -0
- package/dist/lookup.d.cts +4 -0
- package/dist/lookup.js +7 -7
- package/dist/lookup.js.map +1 -1
- package/dist/node/index.cjs +726 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +56 -0
- package/dist/node/index.d.ts +56 -0
- package/dist/{telegram/provider.js → node/index.js} +521 -216
- package/dist/node/index.js.map +1 -0
- package/dist/policies-DD1aPjQ4.d.cts +21 -0
- package/dist/policies-DD1aPjQ4.d.ts +21 -0
- package/dist/{types-CVnDQVqD.d.ts → provider-ap1C1ypF.d.cts} +27 -10
- package/dist/provider-ap1C1ypF.d.ts +201 -0
- package/dist/session/{provider.js → index.cjs} +342 -168
- package/dist/session/index.cjs.map +1 -0
- package/dist/session/index.d.cts +38 -0
- package/dist/session/index.d.ts +37 -7
- package/dist/session/index.js +309 -161
- package/dist/session/index.js.map +1 -1
- package/package.json +49 -16
- package/src/controller.ts +44 -15
- package/src/iframe/base.ts +1 -11
- package/src/mutex.ts +22 -0
- package/src/node/account.ts +72 -0
- package/src/node/backend.ts +159 -0
- package/src/node/index.ts +4 -0
- package/src/node/provider.ts +178 -0
- package/src/node/server.ts +89 -0
- package/src/policies.ts +49 -0
- package/src/provider.ts +33 -2
- package/src/session/account.ts +2 -1
- package/src/session/provider.ts +123 -10
- package/src/telegram/provider.ts +3 -2
- package/src/types.ts +3 -6
- package/src/utils.ts +4 -1
- package/tsconfig.json +3 -3
- package/dist/__tests__/parseChainId.test.d.ts +0 -2
- package/dist/__tests__/parseChainId.test.js +0 -89
- package/dist/__tests__/parseChainId.test.js.map +0 -1
- package/dist/account.d.ts +0 -38
- package/dist/account.js +0 -106
- package/dist/account.js.map +0 -1
- package/dist/constants.d.ts +0 -5
- package/dist/constants.js +0 -10
- package/dist/constants.js.map +0 -1
- package/dist/errors.d.ts +0 -5
- package/dist/errors.js +0 -11
- package/dist/errors.js.map +0 -1
- package/dist/icon.d.ts +0 -3
- package/dist/icon.js +0 -6
- package/dist/icon.js.map +0 -1
- package/dist/iframe/base.d.ts +0 -5
- package/dist/iframe/base.js +0 -122
- package/dist/iframe/base.js.map +0 -1
- package/dist/iframe/index.d.ts +0 -5
- package/dist/iframe/index.js +0 -184
- package/dist/iframe/index.js.map +0 -1
- package/dist/iframe/keychain.d.ts +0 -5
- package/dist/iframe/keychain.js +0 -143
- package/dist/iframe/keychain.js.map +0 -1
- package/dist/iframe/profile.d.ts +0 -5
- package/dist/iframe/profile.js +0 -163
- package/dist/iframe/profile.js.map +0 -1
- package/dist/index.d-BbTUPBeO.d.ts +0 -68
- package/dist/provider.d.ts +0 -22
- package/dist/provider.js +0 -198
- package/dist/provider.js.map +0 -1
- package/dist/session/account.d.ts +0 -37
- package/dist/session/account.js +0 -92
- package/dist/session/account.js.map +0 -1
- package/dist/session/backend.d.ts +0 -60
- package/dist/session/backend.js +0 -39
- package/dist/session/backend.js.map +0 -1
- package/dist/session/provider.d.ts +0 -30
- package/dist/session/provider.js.map +0 -1
- package/dist/telegram/backend.d.ts +0 -33
- package/dist/telegram/backend.js +0 -40
- package/dist/telegram/backend.js.map +0 -1
- package/dist/telegram/provider.d.ts +0 -26
- package/dist/telegram/provider.js.map +0 -1
- package/dist/types.d.ts +0 -5
- package/dist/types.js +0 -13
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -18
- package/dist/utils.js +0 -139
- package/dist/utils.js.map +0 -1
package/dist/utils.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as starknet from 'starknet';
|
|
2
|
-
import { Call } from 'starknet';
|
|
3
|
-
import wasm from '@cartridge/account-wasm/controller';
|
|
4
|
-
import { P as Policies, S as SessionPolicies } from './index.d-BbTUPBeO.js';
|
|
5
|
-
import { ChainId } from '@starknet-io/types-js';
|
|
6
|
-
|
|
7
|
-
declare function normalizeCalls(calls: Call | Call[]): {
|
|
8
|
-
entrypoint: string;
|
|
9
|
-
contractAddress: string;
|
|
10
|
-
calldata: starknet.HexCalldata;
|
|
11
|
-
}[];
|
|
12
|
-
declare function toSessionPolicies(policies: Policies): SessionPolicies;
|
|
13
|
-
declare function toWasmPolicies(policies: SessionPolicies): wasm.Policy[];
|
|
14
|
-
declare function toArray<T>(val: T | T[]): T[];
|
|
15
|
-
declare function humanizeString(str: string): string;
|
|
16
|
-
declare function parseChainId(url: URL): ChainId;
|
|
17
|
-
|
|
18
|
-
export { humanizeString, normalizeCalls, parseChainId, toArray, toSessionPolicies, toWasmPolicies };
|
package/dist/utils.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
// src/utils.ts
|
|
2
|
-
import {
|
|
3
|
-
addAddressPadding,
|
|
4
|
-
CallData,
|
|
5
|
-
constants,
|
|
6
|
-
getChecksumAddress,
|
|
7
|
-
hash,
|
|
8
|
-
shortString,
|
|
9
|
-
typedData,
|
|
10
|
-
TypedDataRevision
|
|
11
|
-
} from "starknet";
|
|
12
|
-
var ALLOWED_PROPERTIES = /* @__PURE__ */ new Set([
|
|
13
|
-
"contracts",
|
|
14
|
-
"messages",
|
|
15
|
-
"target",
|
|
16
|
-
"method",
|
|
17
|
-
"name",
|
|
18
|
-
"description",
|
|
19
|
-
"types",
|
|
20
|
-
"domain",
|
|
21
|
-
"primaryType"
|
|
22
|
-
]);
|
|
23
|
-
function validatePropertyName(prop) {
|
|
24
|
-
if (!ALLOWED_PROPERTIES.has(prop)) {
|
|
25
|
-
throw new Error(`Invalid property name: ${prop}`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function safeObjectAccess(obj, prop) {
|
|
29
|
-
validatePropertyName(prop);
|
|
30
|
-
return obj[prop];
|
|
31
|
-
}
|
|
32
|
-
function normalizeCalls(calls) {
|
|
33
|
-
return toArray(calls).map((call) => {
|
|
34
|
-
return {
|
|
35
|
-
entrypoint: call.entrypoint,
|
|
36
|
-
contractAddress: addAddressPadding(call.contractAddress),
|
|
37
|
-
calldata: CallData.toHex(call.calldata)
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function toSessionPolicies(policies) {
|
|
42
|
-
return Array.isArray(policies) ? policies.reduce(
|
|
43
|
-
(prev, p) => {
|
|
44
|
-
if (safeObjectAccess(p, "target")) {
|
|
45
|
-
const target = getChecksumAddress(
|
|
46
|
-
safeObjectAccess(p, "target")
|
|
47
|
-
);
|
|
48
|
-
const entrypoint = safeObjectAccess(p, "method");
|
|
49
|
-
const contracts = safeObjectAccess(
|
|
50
|
-
prev,
|
|
51
|
-
"contracts"
|
|
52
|
-
);
|
|
53
|
-
const item = {
|
|
54
|
-
name: humanizeString(entrypoint),
|
|
55
|
-
entrypoint,
|
|
56
|
-
description: safeObjectAccess(p, "description")
|
|
57
|
-
};
|
|
58
|
-
if (target in contracts) {
|
|
59
|
-
const methods = toArray(contracts[target].methods);
|
|
60
|
-
contracts[target] = {
|
|
61
|
-
methods: [...methods, item]
|
|
62
|
-
};
|
|
63
|
-
} else {
|
|
64
|
-
contracts[target] = {
|
|
65
|
-
methods: [item]
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
const messages = safeObjectAccess(prev, "messages");
|
|
70
|
-
messages.push(p);
|
|
71
|
-
}
|
|
72
|
-
return prev;
|
|
73
|
-
},
|
|
74
|
-
{ contracts: {}, messages: [] }
|
|
75
|
-
) : policies;
|
|
76
|
-
}
|
|
77
|
-
function toWasmPolicies(policies) {
|
|
78
|
-
return [
|
|
79
|
-
...Object.entries(policies.contracts ?? {}).flatMap(
|
|
80
|
-
([target, { methods }]) => toArray(methods).map((m) => ({
|
|
81
|
-
target,
|
|
82
|
-
method: m.entrypoint
|
|
83
|
-
}))
|
|
84
|
-
),
|
|
85
|
-
...(policies.messages ?? []).map((p) => {
|
|
86
|
-
const domainHash = typedData.getStructHash(
|
|
87
|
-
p.types,
|
|
88
|
-
"StarknetDomain",
|
|
89
|
-
p.domain,
|
|
90
|
-
TypedDataRevision.ACTIVE
|
|
91
|
-
);
|
|
92
|
-
const typeHash = typedData.getTypeHash(
|
|
93
|
-
p.types,
|
|
94
|
-
p.primaryType,
|
|
95
|
-
TypedDataRevision.ACTIVE
|
|
96
|
-
);
|
|
97
|
-
return {
|
|
98
|
-
scope_hash: hash.computePoseidonHash(domainHash, typeHash)
|
|
99
|
-
};
|
|
100
|
-
})
|
|
101
|
-
];
|
|
102
|
-
}
|
|
103
|
-
function toArray(val) {
|
|
104
|
-
return Array.isArray(val) ? val : [val];
|
|
105
|
-
}
|
|
106
|
-
function humanizeString(str) {
|
|
107
|
-
return str.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/_/g, " ").toLowerCase().replace(/^\w/, (c) => c.toUpperCase());
|
|
108
|
-
}
|
|
109
|
-
function parseChainId(url) {
|
|
110
|
-
const parts = url.pathname.split("/");
|
|
111
|
-
if (parts.includes("starknet")) {
|
|
112
|
-
if (parts.includes("mainnet")) {
|
|
113
|
-
return constants.StarknetChainId.SN_MAIN;
|
|
114
|
-
} else if (parts.includes("sepolia")) {
|
|
115
|
-
return constants.StarknetChainId.SN_SEPOLIA;
|
|
116
|
-
}
|
|
117
|
-
} else if (parts.length >= 3) {
|
|
118
|
-
const projectName = parts[2];
|
|
119
|
-
if (parts.includes("katana")) {
|
|
120
|
-
return shortString.encodeShortString(
|
|
121
|
-
`WP_${projectName.toUpperCase().replace(/-/g, "_")}`
|
|
122
|
-
);
|
|
123
|
-
} else if (parts.includes("mainnet")) {
|
|
124
|
-
return shortString.encodeShortString(
|
|
125
|
-
`GG_${projectName.toUpperCase().replace(/-/g, "_")}`
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
throw new Error(`Chain ${url.toString()} not supported`);
|
|
130
|
-
}
|
|
131
|
-
export {
|
|
132
|
-
humanizeString,
|
|
133
|
-
normalizeCalls,
|
|
134
|
-
parseChainId,
|
|
135
|
-
toArray,
|
|
136
|
-
toSessionPolicies,
|
|
137
|
-
toWasmPolicies
|
|
138
|
-
};
|
|
139
|
-
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import {\n addAddressPadding,\n Call,\n CallData,\n constants,\n getChecksumAddress,\n hash,\n shortString,\n typedData,\n TypedDataRevision,\n} from \"starknet\";\nimport wasm from \"@cartridge/account-wasm/controller\";\nimport { Policies, SessionPolicies } from \"@cartridge/presets\";\nimport { ChainId } from \"@starknet-io/types-js\";\n\n// Whitelist of allowed property names to prevent prototype pollution\nconst ALLOWED_PROPERTIES = new Set([\n \"contracts\",\n \"messages\",\n \"target\",\n \"method\",\n \"name\",\n \"description\",\n \"types\",\n \"domain\",\n \"primaryType\",\n]);\n\nfunction validatePropertyName(prop: string): void {\n if (!ALLOWED_PROPERTIES.has(prop)) {\n throw new Error(`Invalid property name: ${prop}`);\n }\n}\n\nfunction safeObjectAccess<T>(obj: any, prop: string): T {\n validatePropertyName(prop);\n return obj[prop];\n}\n\nexport function normalizeCalls(calls: Call | Call[]) {\n return toArray(calls).map((call) => {\n return {\n entrypoint: call.entrypoint,\n contractAddress: addAddressPadding(call.contractAddress),\n calldata: CallData.toHex(call.calldata),\n };\n });\n}\n\nexport function toSessionPolicies(policies: Policies): SessionPolicies {\n return Array.isArray(policies)\n ? policies.reduce<SessionPolicies>(\n (prev, p) => {\n if (safeObjectAccess<string>(p, \"target\")) {\n const target = getChecksumAddress(\n safeObjectAccess<string>(p, \"target\"),\n );\n const entrypoint = safeObjectAccess<string>(p, \"method\");\n const contracts = safeObjectAccess<Record<string, any>>(\n prev,\n \"contracts\",\n );\n const item = {\n name: humanizeString(entrypoint),\n entrypoint: entrypoint,\n description: safeObjectAccess<string>(p, \"description\"),\n };\n\n if (target in contracts) {\n const methods = toArray(contracts[target].methods);\n contracts[target] = {\n methods: [...methods, item],\n };\n } else {\n contracts[target] = {\n methods: [item],\n };\n }\n } else {\n const messages = safeObjectAccess<any[]>(prev, \"messages\");\n messages.push(p);\n }\n\n return prev;\n },\n { contracts: {}, messages: [] },\n )\n : policies;\n}\n\nexport function toWasmPolicies(policies: SessionPolicies): wasm.Policy[] {\n return [\n ...Object.entries(policies.contracts ?? {}).flatMap(\n ([target, { methods }]) =>\n toArray(methods).map((m) => ({\n target,\n method: m.entrypoint,\n })),\n ),\n ...(policies.messages ?? []).map((p) => {\n const domainHash = typedData.getStructHash(\n p.types,\n \"StarknetDomain\",\n p.domain,\n TypedDataRevision.ACTIVE,\n );\n const typeHash = typedData.getTypeHash(\n p.types,\n p.primaryType,\n TypedDataRevision.ACTIVE,\n );\n\n return {\n scope_hash: hash.computePoseidonHash(domainHash, typeHash),\n };\n }),\n ];\n}\n\nexport function toArray<T>(val: T | T[]): T[] {\n return Array.isArray(val) ? val : [val];\n}\n\nexport function humanizeString(str: string): string {\n return (\n str\n // Convert from camelCase or snake_case\n .replace(/([a-z])([A-Z])/g, \"$1 $2\") // camelCase to spaces\n .replace(/_/g, \" \") // snake_case to spaces\n .toLowerCase()\n // Capitalize first letter\n .replace(/^\\w/, (c) => c.toUpperCase())\n );\n}\n\nexport function parseChainId(url: URL): ChainId {\n const parts = url.pathname.split(\"/\");\n\n if (parts.includes(\"starknet\")) {\n if (parts.includes(\"mainnet\")) {\n return constants.StarknetChainId.SN_MAIN;\n } else if (parts.includes(\"sepolia\")) {\n return constants.StarknetChainId.SN_SEPOLIA;\n }\n } else if (parts.length >= 3) {\n const projectName = parts[2];\n if (parts.includes(\"katana\")) {\n return shortString.encodeShortString(\n `WP_${projectName.toUpperCase().replace(/-/g, \"_\")}`,\n ) as ChainId;\n } else if (parts.includes(\"mainnet\")) {\n return shortString.encodeShortString(\n `GG_${projectName.toUpperCase().replace(/-/g, \"_\")}`,\n ) as ChainId;\n }\n }\n\n throw new Error(`Chain ${url.toString()} not supported`);\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMP,IAAM,qBAAqB,oBAAI,IAAI;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,qBAAqB,MAAoB;AAChD,MAAI,CAAC,mBAAmB,IAAI,IAAI,GAAG;AACjC,UAAM,IAAI,MAAM,0BAA0B,IAAI,EAAE;AAAA,EAClD;AACF;AAEA,SAAS,iBAAoB,KAAU,MAAiB;AACtD,uBAAqB,IAAI;AACzB,SAAO,IAAI,IAAI;AACjB;AAEO,SAAS,eAAe,OAAsB;AACnD,SAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,SAAS;AAClC,WAAO;AAAA,MACL,YAAY,KAAK;AAAA,MACjB,iBAAiB,kBAAkB,KAAK,eAAe;AAAA,MACvD,UAAU,SAAS,MAAM,KAAK,QAAQ;AAAA,IACxC;AAAA,EACF,CAAC;AACH;AAEO,SAAS,kBAAkB,UAAqC;AACrE,SAAO,MAAM,QAAQ,QAAQ,IACzB,SAAS;AAAA,IACP,CAAC,MAAM,MAAM;AACX,UAAI,iBAAyB,GAAG,QAAQ,GAAG;AACzC,cAAM,SAAS;AAAA,UACb,iBAAyB,GAAG,QAAQ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