@cartridge/controller-wasm 0.1.0 → 0.1.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/package.json +48 -4
- package/pkg-controller/account_wasm.d.ts +252 -0
- package/pkg-controller/account_wasm.js +4 -0
- package/pkg-controller/account_wasm_bg.js +1558 -0
- package/pkg-controller/account_wasm_bg.wasm +0 -0
- package/{account_wasm.d.ts → pkg-session/session_wasm.d.ts} +9 -0
- package/pkg-session/session_wasm.js +4 -0
- package/pkg-session/session_wasm_bg.js +1114 -0
- package/pkg-session/session_wasm_bg.wasm +0 -0
- package/.gitignore +0 -1
- package/account_wasm.js +0 -259
- package/account_wasm_bg.wasm +0 -0
- package/account_wasm_bg.wasm.d.ts +0 -14
- package/snippets/account-wasm-35da9c7350cbc3ae/src/wasm-mutex.js +0 -13
package/package.json
CHANGED
|
@@ -1,9 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cartridge/controller-wasm",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Wasm bindings for Cartridge Controller and Session Account",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./pkg-controller/account_wasm.js",
|
|
7
|
+
"module": "./pkg-controller/account_wasm.js",
|
|
8
|
+
"types": "./pkg-controller/account_wasm.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build:deps": "./build.sh"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"./pkg-controller/account_wasm_bg.wasm",
|
|
14
|
+
"./pkg-controller/account_wasm.js",
|
|
15
|
+
"./pkg-controller/account_wasm_bg.js",
|
|
16
|
+
"./pkg-controller/account_wasm.d.ts",
|
|
17
|
+
"./pkg-controller/snippets/**/*",
|
|
18
|
+
"./pkg-session/session_wasm_bg.wasm",
|
|
19
|
+
"./pkg-session/session_wasm.js",
|
|
20
|
+
"./pkg-session/session_wasm_bg.js",
|
|
21
|
+
"./pkg-session/session_wasm.d.ts",
|
|
22
|
+
"./pkg-session/snippets/**/*"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./pkg-controller/account_wasm.d.ts",
|
|
27
|
+
"import": "./pkg-controller/account_wasm.js",
|
|
28
|
+
"require": "./pkg-controller/account_wasm.js"
|
|
29
|
+
},
|
|
30
|
+
"./controller": {
|
|
31
|
+
"types": "./pkg-controller/account_wasm.d.ts",
|
|
32
|
+
"import": "./pkg-controller/account_wasm.js",
|
|
33
|
+
"require": "./pkg-controller/account_wasm.js"
|
|
34
|
+
},
|
|
35
|
+
"./session": {
|
|
36
|
+
"types": "./pkg-session/session_wasm.d.ts",
|
|
37
|
+
"import": "./pkg-session/session_wasm.js",
|
|
38
|
+
"require": "./pkg-session/session_wasm.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"sideEffects": [
|
|
42
|
+
"./pkg-controller/account_wasm.js",
|
|
43
|
+
"./pkg-session/session_wasm.js",
|
|
44
|
+
"./pkg-controller/snippets/*",
|
|
45
|
+
"./pkg-session/snippets/*"
|
|
46
|
+
],
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"wasm-pack": "^0.13.0"
|
|
49
|
+
},
|
|
50
|
+
"packageManager": "pnpm@9.12.3+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee",
|
|
7
51
|
"repository": "https://github.com/cartridge-gg/controller-rs",
|
|
8
52
|
"license": "MIT"
|
|
9
53
|
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Computes the Starknet contract address for a controller account without needing a full instance.
|
|
5
|
+
*
|
|
6
|
+
* # Arguments
|
|
7
|
+
*
|
|
8
|
+
* * `class_hash` - The class hash of the account contract (JsFelt).
|
|
9
|
+
* * `owner` - The owner configuration for the account.
|
|
10
|
+
* * `salt` - The salt used for address calculation (JsFelt).
|
|
11
|
+
*
|
|
12
|
+
* # Returns
|
|
13
|
+
*
|
|
14
|
+
* The computed Starknet contract address as a `JsFelt`.
|
|
15
|
+
*/
|
|
16
|
+
export function computeAccountAddress(class_hash: JsFelt, owner: Owner, salt: JsFelt): JsFelt;
|
|
17
|
+
export enum ErrorCode {
|
|
18
|
+
StarknetFailedToReceiveTransaction = 1,
|
|
19
|
+
StarknetContractNotFound = 20,
|
|
20
|
+
StarknetBlockNotFound = 24,
|
|
21
|
+
StarknetInvalidTransactionIndex = 27,
|
|
22
|
+
StarknetClassHashNotFound = 28,
|
|
23
|
+
StarknetTransactionHashNotFound = 29,
|
|
24
|
+
StarknetPageSizeTooBig = 31,
|
|
25
|
+
StarknetNoBlocks = 32,
|
|
26
|
+
StarknetInvalidContinuationToken = 33,
|
|
27
|
+
StarknetTooManyKeysInFilter = 34,
|
|
28
|
+
StarknetContractError = 40,
|
|
29
|
+
StarknetTransactionExecutionError = 41,
|
|
30
|
+
StarknetClassAlreadyDeclared = 51,
|
|
31
|
+
StarknetInvalidTransactionNonce = 52,
|
|
32
|
+
StarknetInsufficientMaxFee = 53,
|
|
33
|
+
StarknetInsufficientAccountBalance = 54,
|
|
34
|
+
StarknetValidationFailure = 55,
|
|
35
|
+
StarknetCompilationFailed = 56,
|
|
36
|
+
StarknetContractClassSizeIsTooLarge = 57,
|
|
37
|
+
StarknetNonAccount = 58,
|
|
38
|
+
StarknetDuplicateTx = 59,
|
|
39
|
+
StarknetCompiledClassHashMismatch = 60,
|
|
40
|
+
StarknetUnsupportedTxVersion = 61,
|
|
41
|
+
StarknetUnsupportedContractClassVersion = 62,
|
|
42
|
+
StarknetUnexpectedError = 63,
|
|
43
|
+
StarknetNoTraceAvailable = 10,
|
|
44
|
+
SignError = 101,
|
|
45
|
+
StorageError = 102,
|
|
46
|
+
AccountFactoryError = 103,
|
|
47
|
+
PaymasterExecutionTimeNotReached = 104,
|
|
48
|
+
PaymasterExecutionTimePassed = 105,
|
|
49
|
+
PaymasterInvalidCaller = 106,
|
|
50
|
+
PaymasterRateLimitExceeded = 107,
|
|
51
|
+
PaymasterNotSupported = 108,
|
|
52
|
+
PaymasterHttp = 109,
|
|
53
|
+
PaymasterExcecution = 110,
|
|
54
|
+
PaymasterSerialization = 111,
|
|
55
|
+
CartridgeControllerNotDeployed = 112,
|
|
56
|
+
InsufficientBalance = 113,
|
|
57
|
+
OriginError = 114,
|
|
58
|
+
EncodingError = 115,
|
|
59
|
+
SerdeWasmBindgenError = 116,
|
|
60
|
+
CairoSerdeError = 117,
|
|
61
|
+
CairoShortStringToFeltError = 118,
|
|
62
|
+
DeviceCreateCredential = 119,
|
|
63
|
+
DeviceGetAssertion = 120,
|
|
64
|
+
DeviceBadAssertion = 121,
|
|
65
|
+
DeviceChannel = 122,
|
|
66
|
+
DeviceOrigin = 123,
|
|
67
|
+
AccountSigning = 124,
|
|
68
|
+
AccountProvider = 125,
|
|
69
|
+
AccountClassHashCalculation = 126,
|
|
70
|
+
AccountClassCompression = 127,
|
|
71
|
+
AccountFeeOutOfRange = 128,
|
|
72
|
+
ProviderRateLimited = 129,
|
|
73
|
+
ProviderArrayLengthMismatch = 130,
|
|
74
|
+
ProviderOther = 131,
|
|
75
|
+
SessionAlreadyRegistered = 132,
|
|
76
|
+
UrlParseError = 133,
|
|
77
|
+
Base64DecodeError = 134,
|
|
78
|
+
CoseError = 135,
|
|
79
|
+
PolicyChainIdMismatch = 136,
|
|
80
|
+
}
|
|
81
|
+
export interface JsCall {
|
|
82
|
+
contractAddress: JsFelt;
|
|
83
|
+
entrypoint: string;
|
|
84
|
+
calldata: JsFelt[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type JsPriceUnit = "WEI" | "FRI";
|
|
88
|
+
|
|
89
|
+
export interface JsEstimateFeeDetails {
|
|
90
|
+
nonce: JsFelt;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface JsFeeEstimate {
|
|
94
|
+
gas_consumed: JsFelt;
|
|
95
|
+
gas_price: JsFelt;
|
|
96
|
+
overall_fee: JsFelt;
|
|
97
|
+
unit: JsPriceUnit;
|
|
98
|
+
data_gas_consumed: JsFelt;
|
|
99
|
+
data_gas_price: JsFelt;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface Owner {
|
|
103
|
+
signer?: Signer;
|
|
104
|
+
account?: JsFelt;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface CallPolicy {
|
|
108
|
+
target: JsFelt;
|
|
109
|
+
method: JsFelt;
|
|
110
|
+
authorized?: boolean;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface TypedDataPolicy {
|
|
114
|
+
scope_hash: JsFelt;
|
|
115
|
+
authorized?: boolean;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export type Policy = CallPolicy | TypedDataPolicy;
|
|
119
|
+
|
|
120
|
+
export interface WebauthnSigner {
|
|
121
|
+
rpId: string;
|
|
122
|
+
credentialId: string;
|
|
123
|
+
publicKey: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface StarknetSigner {
|
|
127
|
+
privateKey: JsFelt;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface Eip191Signer {
|
|
131
|
+
address: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface Signer {
|
|
135
|
+
webauthn?: WebauthnSigner;
|
|
136
|
+
starknet?: StarknetSigner;
|
|
137
|
+
eip191?: Eip191Signer;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export type JsFelt = Felt;
|
|
141
|
+
|
|
142
|
+
export type Felts = JsFelt[];
|
|
143
|
+
|
|
144
|
+
export type JsFeeSource = "PAYMASTER" | "CREDITS";
|
|
145
|
+
|
|
146
|
+
export interface AuthorizedSession {
|
|
147
|
+
session: Session;
|
|
148
|
+
authorization: JsFelt[] | null;
|
|
149
|
+
isRegistered: boolean;
|
|
150
|
+
expiresAt: number;
|
|
151
|
+
allowedPoliciesRoot: JsFelt;
|
|
152
|
+
metadataHash: JsFelt;
|
|
153
|
+
sessionKeyGuid: JsFelt;
|
|
154
|
+
guardianKeyGuid: JsFelt;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface Session {
|
|
158
|
+
policies: Policy[];
|
|
159
|
+
expiresAt: number;
|
|
160
|
+
metadataHash: JsFelt;
|
|
161
|
+
sessionKeyGuid: JsFelt;
|
|
162
|
+
guardianKeyGuid: JsFelt;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface Credentials {
|
|
166
|
+
authorization: JsFelt[];
|
|
167
|
+
privateKey: JsFelt;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export class CartridgeAccount {
|
|
171
|
+
private constructor();
|
|
172
|
+
free(): void;
|
|
173
|
+
/**
|
|
174
|
+
* Creates a new `CartridgeAccount` instance.
|
|
175
|
+
*
|
|
176
|
+
* # Parameters
|
|
177
|
+
* - `app_id`: Application identifier.
|
|
178
|
+
* - `rpc_url`: The URL of the JSON-RPC endpoint.
|
|
179
|
+
* - `chain_id`: Identifier of the blockchain network to interact with.
|
|
180
|
+
* - `address`: The blockchain address associated with the account.
|
|
181
|
+
* - `username`: Username associated with the account.
|
|
182
|
+
* - `owner`: A Owner struct containing the owner signer and associated data.
|
|
183
|
+
*/
|
|
184
|
+
static new(app_id: string, class_hash: JsFelt, rpc_url: string, chain_id: JsFelt, address: JsFelt, username: string, owner: Owner): CartridgeAccountWithMeta;
|
|
185
|
+
static fromStorage(app_id: string): CartridgeAccountWithMeta | undefined;
|
|
186
|
+
disconnect(): Promise<void>;
|
|
187
|
+
registerSession(policies: Policy[], expires_at: bigint, public_key: JsFelt, max_fee?: JsFeeEstimate | null): Promise<any>;
|
|
188
|
+
registerSessionCalldata(policies: Policy[], expires_at: bigint, public_key: JsFelt): Promise<any>;
|
|
189
|
+
upgrade(new_class_hash: JsFelt): Promise<JsCall>;
|
|
190
|
+
login(expires_at: bigint): Promise<AuthorizedSession>;
|
|
191
|
+
createSession(policies: Policy[], expires_at: bigint): Promise<AuthorizedSession | undefined>;
|
|
192
|
+
skipSession(policies: Policy[]): Promise<void>;
|
|
193
|
+
estimateInvokeFee(calls: JsCall[]): Promise<JsFeeEstimate>;
|
|
194
|
+
execute(calls: JsCall[], max_fee?: JsFeeEstimate | null, fee_source?: JsFeeSource | null): Promise<any>;
|
|
195
|
+
executeFromOutsideV2(calls: JsCall[], fee_source?: JsFeeSource | null): Promise<any>;
|
|
196
|
+
executeFromOutsideV3(calls: JsCall[], fee_source?: JsFeeSource | null): Promise<any>;
|
|
197
|
+
isRegisteredSessionAuthorized(policies: Policy[], public_key?: JsFelt | null): Promise<AuthorizedSession | undefined>;
|
|
198
|
+
hasRequestedSession(policies: Policy[]): Promise<boolean>;
|
|
199
|
+
revokeSession(): void;
|
|
200
|
+
signMessage(typed_data: string): Promise<Felts>;
|
|
201
|
+
getNonce(): Promise<any>;
|
|
202
|
+
deploySelf(max_fee?: JsFeeEstimate | null): Promise<any>;
|
|
203
|
+
delegateAccount(): Promise<JsFelt>;
|
|
204
|
+
hasAuthorizedPoliciesForCalls(calls: JsCall[]): Promise<boolean>;
|
|
205
|
+
hasAuthorizedPoliciesForMessage(typed_data: string): Promise<boolean>;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* A type for accessing fixed attributes of `CartridgeAccount`.
|
|
209
|
+
*
|
|
210
|
+
* This type exists as concurrent mutable and immutable calls to `CartridgeAccount` are guarded
|
|
211
|
+
* with `WasmMutex`, which only operates under an `async` context. If these getters were directly
|
|
212
|
+
* implemented under `CartridgeAccount`:
|
|
213
|
+
*
|
|
214
|
+
* - calls to them would unnecessarily have to be `async` as well;
|
|
215
|
+
* - there would be excessive locking.
|
|
216
|
+
*
|
|
217
|
+
* This type is supposed to only ever be borrowed immutably. So no concurrent access control would
|
|
218
|
+
* be needed.
|
|
219
|
+
*/
|
|
220
|
+
export class CartridgeAccountMeta {
|
|
221
|
+
private constructor();
|
|
222
|
+
free(): void;
|
|
223
|
+
appId(): string;
|
|
224
|
+
username(): string;
|
|
225
|
+
address(): string;
|
|
226
|
+
classHash(): string;
|
|
227
|
+
rpcUrl(): string;
|
|
228
|
+
chainId(): string;
|
|
229
|
+
ownerGuid(): JsFelt;
|
|
230
|
+
owner(): Owner;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* A type used as the return type for constructing `CartridgeAccount` to provide an extra,
|
|
234
|
+
* separately borrowable `meta` field for synchronously accessing fixed fields.
|
|
235
|
+
*
|
|
236
|
+
* This type exists instead of simply having `CartridgeAccount::new()` return a tuple as tuples
|
|
237
|
+
* don't implement `IntoWasmAbi` which is needed for crossing JS-WASM boundary.
|
|
238
|
+
*/
|
|
239
|
+
export class CartridgeAccountWithMeta {
|
|
240
|
+
private constructor();
|
|
241
|
+
free(): void;
|
|
242
|
+
meta(): CartridgeAccountMeta;
|
|
243
|
+
intoAccount(): CartridgeAccount;
|
|
244
|
+
}
|
|
245
|
+
export class JsControllerError {
|
|
246
|
+
private constructor();
|
|
247
|
+
free(): void;
|
|
248
|
+
code: ErrorCode;
|
|
249
|
+
message: string;
|
|
250
|
+
get data(): string | undefined;
|
|
251
|
+
set data(value: string | null | undefined);
|
|
252
|
+
}
|