@cartridge/controller 0.4.0 → 0.5.0-alpha.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 +1 -1
- package/dist/account.d.ts +35 -0
- package/dist/{device.js → account.js} +14 -33
- package/dist/account.js.map +1 -0
- package/dist/constants.d.ts +0 -2
- package/dist/constants.js +0 -2
- package/dist/constants.js.map +1 -1
- package/dist/controller.d.ts +7 -14
- package/dist/controller.js +41 -53
- package/dist/controller.js.map +1 -1
- package/dist/errors.d.ts +0 -3
- package/dist/errors.js +0 -6
- package/dist/errors.js.map +1 -1
- package/dist/icon.d.ts +1 -0
- package/dist/icon.js +2 -0
- package/dist/icon.js.map +1 -0
- package/dist/iframe/base.d.ts +0 -1
- package/dist/iframe/base.js +21 -11
- package/dist/iframe/base.js.map +1 -1
- package/dist/iframe/keychain.d.ts +1 -1
- package/dist/iframe/keychain.js +1 -4
- package/dist/iframe/keychain.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +18 -0
- package/dist/provider.js +128 -0
- package/dist/provider.js.map +1 -0
- package/dist/session/account.d.ts +32 -0
- package/dist/session/account.js +31 -0
- package/dist/session/account.js.map +1 -0
- package/dist/session/backend.d.ts +58 -0
- package/dist/session/backend.js +38 -0
- package/dist/session/backend.js.map +1 -0
- package/dist/session/index.d.ts +5 -0
- package/dist/session/index.js +6 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/provider.d.ts +25 -0
- package/dist/session/provider.js +89 -0
- package/dist/session/provider.js.map +1 -0
- package/dist/telegram/backend.d.ts +30 -0
- package/dist/telegram/backend.js +39 -0
- package/dist/telegram/backend.js.map +1 -0
- package/dist/telegram/provider.d.ts +19 -0
- package/dist/telegram/provider.js +78 -0
- package/dist/telegram/provider.js.map +1 -0
- package/dist/types.d.ts +12 -31
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +0 -2
- package/dist/utils.js +0 -4
- package/dist/utils.js.map +1 -1
- package/package.json +11 -9
- package/src/{device.ts → account.ts} +23 -66
- package/src/constants.ts +0 -2
- package/src/controller.ts +50 -79
- package/src/errors.ts +0 -8
- package/src/icon.ts +2 -0
- package/src/iframe/base.ts +27 -12
- package/src/iframe/keychain.ts +2 -12
- package/src/index.ts +5 -0
- package/src/provider.ts +181 -0
- package/src/session/account.ts +65 -0
- package/src/session/backend.ts +73 -0
- package/src/session/index.ts +6 -0
- package/src/session/provider.ts +141 -0
- package/src/telegram/backend.ts +43 -0
- package/src/telegram/provider.ts +131 -0
- package/src/types.ts +18 -66
- package/src/utils.ts +0 -10
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/device.d.ts +0 -46
- package/dist/device.js.map +0 -1
- package/dist/session.d.ts +0 -40
- package/dist/session.js +0 -44
- package/dist/session.js.map +0 -1
- package/dist/signer.d.ts +0 -53
- package/dist/signer.js +0 -83
- package/dist/signer.js.map +0 -1
- package/src/session.ts +0 -92
- package/src/signer.ts +0 -144
package/dist/session.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Policy } from "@cartridge/account-wasm";
|
|
2
|
-
import { CartridgeSessionAccount } from "@cartridge/account-wasm/session";
|
|
3
|
-
import { Abi, Account, Call, InvokeFunctionResponse, Signature, TypedData, UniversalDetails } from "starknet";
|
|
4
|
-
export * from "./errors";
|
|
5
|
-
export * from "./types";
|
|
6
|
-
export { defaultPresets } from "./presets";
|
|
7
|
-
export default class SessionAccount extends Account {
|
|
8
|
-
controller: CartridgeSessionAccount;
|
|
9
|
-
constructor({ rpcUrl, privateKey, address, ownerGuid, chainId, expiresAt, policies, }: {
|
|
10
|
-
rpcUrl: string;
|
|
11
|
-
privateKey: string;
|
|
12
|
-
address: string;
|
|
13
|
-
ownerGuid: string;
|
|
14
|
-
chainId: string;
|
|
15
|
-
expiresAt: number;
|
|
16
|
-
policies: Policy[];
|
|
17
|
-
});
|
|
18
|
-
/**
|
|
19
|
-
* Invoke execute function in account contract
|
|
20
|
-
*
|
|
21
|
-
* @param calls the invocation object or an array of them, containing:
|
|
22
|
-
* - contractAddress - the address of the contract
|
|
23
|
-
* - entrypoint - the entrypoint of the contract
|
|
24
|
-
* - calldata - (defaults to []) the calldata
|
|
25
|
-
* - signature - (defaults to []) the signature
|
|
26
|
-
* @param abis (optional) the abi of the contract for better displaying
|
|
27
|
-
*
|
|
28
|
-
* @returns response from addTransaction
|
|
29
|
-
*/
|
|
30
|
-
execute(calls: Call | Call[], _abisOrDetails?: Abi[] | UniversalDetails, _transactionsDetail?: UniversalDetails): Promise<InvokeFunctionResponse>;
|
|
31
|
-
/**
|
|
32
|
-
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
33
|
-
* This adds a message prefix so it cant be interchanged with transactions
|
|
34
|
-
*
|
|
35
|
-
* @param json - JSON object to be signed
|
|
36
|
-
* @returns the signature of the JSON object
|
|
37
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
38
|
-
*/
|
|
39
|
-
signMessage(_typedData: TypedData): Promise<Signature>;
|
|
40
|
-
}
|
package/dist/session.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { CartridgeSessionAccount } from "@cartridge/account-wasm/session";
|
|
2
|
-
import { Account, RpcProvider, } from "starknet";
|
|
3
|
-
import { SessionSigner } from "./signer";
|
|
4
|
-
import { normalizeCalls } from "./utils";
|
|
5
|
-
export * from "./errors";
|
|
6
|
-
export * from "./types";
|
|
7
|
-
export { defaultPresets } from "./presets";
|
|
8
|
-
export default class SessionAccount extends Account {
|
|
9
|
-
constructor({ rpcUrl, privateKey, address, ownerGuid, chainId, expiresAt, policies, }) {
|
|
10
|
-
const controller = CartridgeSessionAccount.new_as_registered(rpcUrl, privateKey, address, ownerGuid, chainId, {
|
|
11
|
-
expiresAt,
|
|
12
|
-
policies,
|
|
13
|
-
});
|
|
14
|
-
super(new RpcProvider({ nodeUrl: rpcUrl }), address, new SessionSigner(controller));
|
|
15
|
-
this.controller = controller;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Invoke execute function in account contract
|
|
19
|
-
*
|
|
20
|
-
* @param calls the invocation object or an array of them, containing:
|
|
21
|
-
* - contractAddress - the address of the contract
|
|
22
|
-
* - entrypoint - the entrypoint of the contract
|
|
23
|
-
* - calldata - (defaults to []) the calldata
|
|
24
|
-
* - signature - (defaults to []) the signature
|
|
25
|
-
* @param abis (optional) the abi of the contract for better displaying
|
|
26
|
-
*
|
|
27
|
-
* @returns response from addTransaction
|
|
28
|
-
*/
|
|
29
|
-
async execute(calls, _abisOrDetails, _transactionsDetail) {
|
|
30
|
-
return this.controller.execute(normalizeCalls(calls));
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
34
|
-
* This adds a message prefix so it cant be interchanged with transactions
|
|
35
|
-
*
|
|
36
|
-
* @param json - JSON object to be signed
|
|
37
|
-
* @returns the signature of the JSON object
|
|
38
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
39
|
-
*/
|
|
40
|
-
async signMessage(_typedData) {
|
|
41
|
-
throw new Error("signMessage not implemented for SessionSigner");
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=session.js.map
|
package/dist/session.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAEL,OAAO,EAGP,WAAW,GAIZ,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,OAAO;IAGjD,YAAY,EACV,MAAM,EACN,UAAU,EACV,OAAO,EACP,SAAS,EACT,OAAO,EACP,SAAS,EACT,QAAQ,GAST;QACC,MAAM,UAAU,GAAG,uBAAuB,CAAC,iBAAiB,CAC1D,MAAM,EACN,UAAU,EACV,OAAO,EACP,SAAS,EACT,OAAO,EACP;YACE,SAAS;YACT,QAAQ;SACT,CACF,CAAC;QAEF,KAAK,CACH,IAAI,WAAW,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EACpC,OAAO,EACP,IAAI,aAAa,CAAC,UAAU,CAAC,CAC9B,CAAC;QAEF,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,OAAO,CACX,KAAoB,EACpB,cAAyC,EACzC,mBAAsC;QAEtC,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;IACxD,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,WAAW,CAAC,UAAqB;QACrC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;CACF"}
|
package/dist/signer.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Abi, BigNumberish, Call, DeclareSignerDetails, DeployAccountSignerDetails, InvocationsSignerDetails, Signature, SignerInterface, TypedData } from "starknet";
|
|
2
|
-
import { Keychain, Modal } from "./types";
|
|
3
|
-
import { AsyncMethodReturns } from "@cartridge/penpal";
|
|
4
|
-
import { CartridgeSessionAccount } from "@cartridge/account-wasm/session";
|
|
5
|
-
export declare class Signer implements SignerInterface {
|
|
6
|
-
private keychain;
|
|
7
|
-
modal: Modal;
|
|
8
|
-
constructor(keychain: AsyncMethodReturns<Keychain>, modal: Modal);
|
|
9
|
-
/**
|
|
10
|
-
* Method to get the public key of the signer
|
|
11
|
-
*
|
|
12
|
-
* @returns public key of signer as hex string with 0x prefix
|
|
13
|
-
*/
|
|
14
|
-
getPubKey(): Promise<string>;
|
|
15
|
-
/**
|
|
16
|
-
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
17
|
-
* This adds a message prefix so it cant be interchanged with transactions
|
|
18
|
-
*
|
|
19
|
-
* @param typedData - JSON object to be signed
|
|
20
|
-
* @param accountAddress - account
|
|
21
|
-
* @returns the signature of the JSON object
|
|
22
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
23
|
-
*/
|
|
24
|
-
signMessage(typedData: TypedData, account: string): Promise<Signature>;
|
|
25
|
-
signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
26
|
-
signDeployAccountTransaction(transaction: DeployAccountSignerDetails): Promise<Signature>;
|
|
27
|
-
signDeclareTransaction(transaction: DeclareSignerDetails): Promise<Signature>;
|
|
28
|
-
}
|
|
29
|
-
export declare class SessionSigner implements SignerInterface {
|
|
30
|
-
controller: CartridgeSessionAccount;
|
|
31
|
-
constructor(controller: CartridgeSessionAccount);
|
|
32
|
-
/**
|
|
33
|
-
* Method to get the public key of the signer
|
|
34
|
-
*
|
|
35
|
-
* @returns public key of signer as hex string with 0x prefix
|
|
36
|
-
*/
|
|
37
|
-
getPubKey(): Promise<string>;
|
|
38
|
-
/**
|
|
39
|
-
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
40
|
-
* This adds a message prefix so it cant be interchanged with transactions
|
|
41
|
-
*
|
|
42
|
-
* @param typedData - JSON object to be signed
|
|
43
|
-
* @param accountAddress - account
|
|
44
|
-
* @returns the signature of the JSON object
|
|
45
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
46
|
-
*/
|
|
47
|
-
signMessage(_typedData: TypedData, _account: string): Promise<Signature>;
|
|
48
|
-
signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails & {
|
|
49
|
-
maxFee: BigNumberish;
|
|
50
|
-
}, _abis?: Abi[]): Promise<Signature>;
|
|
51
|
-
signDeployAccountTransaction(_transaction: DeployAccountSignerDetails): Promise<Signature>;
|
|
52
|
-
signDeclareTransaction(_transaction: DeclareSignerDetails): Promise<Signature>;
|
|
53
|
-
}
|
package/dist/signer.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { normalizeCalls } from "./utils";
|
|
2
|
-
export class Signer {
|
|
3
|
-
constructor(keychain, modal) {
|
|
4
|
-
this.keychain = keychain;
|
|
5
|
-
this.modal = modal;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Method to get the public key of the signer
|
|
9
|
-
*
|
|
10
|
-
* @returns public key of signer as hex string with 0x prefix
|
|
11
|
-
*/
|
|
12
|
-
getPubKey() {
|
|
13
|
-
return Promise.resolve("");
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
17
|
-
* This adds a message prefix so it cant be interchanged with transactions
|
|
18
|
-
*
|
|
19
|
-
* @param typedData - JSON object to be signed
|
|
20
|
-
* @param accountAddress - account
|
|
21
|
-
* @returns the signature of the JSON object
|
|
22
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
23
|
-
*/
|
|
24
|
-
async signMessage(typedData, account) {
|
|
25
|
-
this.modal.open();
|
|
26
|
-
const res = await this.keychain.signMessage(typedData, account);
|
|
27
|
-
this.modal.close();
|
|
28
|
-
return res;
|
|
29
|
-
}
|
|
30
|
-
async signTransaction(transactions, transactionsDetail, abis) {
|
|
31
|
-
this.modal.open();
|
|
32
|
-
const res = await this.keychain.signTransaction(transactions, transactionsDetail, abis);
|
|
33
|
-
this.modal.close();
|
|
34
|
-
return res;
|
|
35
|
-
}
|
|
36
|
-
async signDeployAccountTransaction(transaction) {
|
|
37
|
-
this.modal.open();
|
|
38
|
-
const res = await this.keychain.signDeployAccountTransaction(transaction);
|
|
39
|
-
this.modal.close();
|
|
40
|
-
return res;
|
|
41
|
-
}
|
|
42
|
-
async signDeclareTransaction(transaction) {
|
|
43
|
-
this.modal.open();
|
|
44
|
-
const res = await this.keychain.signDeclareTransaction(transaction);
|
|
45
|
-
this.modal.close();
|
|
46
|
-
return res;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
export class SessionSigner {
|
|
50
|
-
constructor(controller) {
|
|
51
|
-
this.controller = controller;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Method to get the public key of the signer
|
|
55
|
-
*
|
|
56
|
-
* @returns public key of signer as hex string with 0x prefix
|
|
57
|
-
*/
|
|
58
|
-
getPubKey() {
|
|
59
|
-
return Promise.resolve("");
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
63
|
-
* This adds a message prefix so it cant be interchanged with transactions
|
|
64
|
-
*
|
|
65
|
-
* @param typedData - JSON object to be signed
|
|
66
|
-
* @param accountAddress - account
|
|
67
|
-
* @returns the signature of the JSON object
|
|
68
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
69
|
-
*/
|
|
70
|
-
async signMessage(_typedData, _account) {
|
|
71
|
-
throw new Error("signMessage not implemented for SessionSigner");
|
|
72
|
-
}
|
|
73
|
-
async signTransaction(transactions, transactionsDetail, _abis) {
|
|
74
|
-
return this.controller.sign_transaction(normalizeCalls(transactions), transactionsDetail.maxFee);
|
|
75
|
-
}
|
|
76
|
-
async signDeployAccountTransaction(_transaction) {
|
|
77
|
-
throw new Error("signDeployAccountTransaction not implemented for SessionSigner");
|
|
78
|
-
}
|
|
79
|
-
async signDeclareTransaction(_transaction) {
|
|
80
|
-
throw new Error("signDeclareTransaction not implemented for SessionSigner");
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
//# sourceMappingURL=signer.js.map
|
package/dist/signer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,OAAO,MAAM;IAGjB,YAAY,QAAsC,EAAE,KAAY;QAC9D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACI,SAAS;QACd,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,WAAW,CACtB,SAAoB,EACpB,OAAe;QAEf,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAChE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,OAAO,GAAgB,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,eAAe,CAC1B,YAAoB,EACpB,kBAA4C,EAC5C,IAAY;QAEZ,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAC7C,YAAY,EACZ,kBAAkB,EAClB,IAAI,CACL,CAAC;QACF,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,OAAO,GAAG,CAAC;IACb,CAAC;IAEM,KAAK,CAAC,4BAA4B,CACvC,WAAuC;QAEvC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,4BAA4B,CAAC,WAAW,CAAC,CAAC;QAC1E,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,OAAO,GAAG,CAAC;IACb,CAAC;IAEM,KAAK,CAAC,sBAAsB,CACjC,WAAiC;QAEjC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAC;QACpE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAED,MAAM,OAAO,aAAa;IAGxB,YAAY,UAAmC;QAC7C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACI,SAAS;QACd,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,WAAW,CACtB,UAAqB,EACrB,QAAgB;QAEhB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAEM,KAAK,CAAC,eAAe,CAC1B,YAAoB,EACpB,kBAAuE,EACvE,KAAa;QAEb,OAAO,IAAI,CAAC,UAAU,CAAC,gBAAgB,CACrC,cAAc,CAAC,YAAY,CAAC,EAC5B,kBAAkB,CAAC,MAAM,CAC1B,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,4BAA4B,CACvC,YAAwC;QAExC,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,sBAAsB,CACjC,YAAkC;QAElC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;CACF"}
|
package/src/session.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { Policy } from "@cartridge/account-wasm";
|
|
2
|
-
import { CartridgeSessionAccount } from "@cartridge/account-wasm/session";
|
|
3
|
-
import {
|
|
4
|
-
Abi,
|
|
5
|
-
Account,
|
|
6
|
-
Call,
|
|
7
|
-
InvokeFunctionResponse,
|
|
8
|
-
RpcProvider,
|
|
9
|
-
Signature,
|
|
10
|
-
TypedData,
|
|
11
|
-
UniversalDetails,
|
|
12
|
-
} from "starknet";
|
|
13
|
-
import { SessionSigner } from "./signer";
|
|
14
|
-
import { normalizeCalls } from "./utils";
|
|
15
|
-
|
|
16
|
-
export * from "./errors";
|
|
17
|
-
export * from "./types";
|
|
18
|
-
export { defaultPresets } from "./presets";
|
|
19
|
-
|
|
20
|
-
export default class SessionAccount extends Account {
|
|
21
|
-
public controller: CartridgeSessionAccount;
|
|
22
|
-
|
|
23
|
-
constructor({
|
|
24
|
-
rpcUrl,
|
|
25
|
-
privateKey,
|
|
26
|
-
address,
|
|
27
|
-
ownerGuid,
|
|
28
|
-
chainId,
|
|
29
|
-
expiresAt,
|
|
30
|
-
policies,
|
|
31
|
-
}: {
|
|
32
|
-
rpcUrl: string;
|
|
33
|
-
privateKey: string;
|
|
34
|
-
address: string;
|
|
35
|
-
ownerGuid: string;
|
|
36
|
-
chainId: string;
|
|
37
|
-
expiresAt: number;
|
|
38
|
-
policies: Policy[];
|
|
39
|
-
}) {
|
|
40
|
-
const controller = CartridgeSessionAccount.new_as_registered(
|
|
41
|
-
rpcUrl,
|
|
42
|
-
privateKey,
|
|
43
|
-
address,
|
|
44
|
-
ownerGuid,
|
|
45
|
-
chainId,
|
|
46
|
-
{
|
|
47
|
-
expiresAt,
|
|
48
|
-
policies,
|
|
49
|
-
},
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
super(
|
|
53
|
-
new RpcProvider({ nodeUrl: rpcUrl }),
|
|
54
|
-
address,
|
|
55
|
-
new SessionSigner(controller),
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
this.controller = controller;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Invoke execute function in account contract
|
|
63
|
-
*
|
|
64
|
-
* @param calls the invocation object or an array of them, containing:
|
|
65
|
-
* - contractAddress - the address of the contract
|
|
66
|
-
* - entrypoint - the entrypoint of the contract
|
|
67
|
-
* - calldata - (defaults to []) the calldata
|
|
68
|
-
* - signature - (defaults to []) the signature
|
|
69
|
-
* @param abis (optional) the abi of the contract for better displaying
|
|
70
|
-
*
|
|
71
|
-
* @returns response from addTransaction
|
|
72
|
-
*/
|
|
73
|
-
async execute(
|
|
74
|
-
calls: Call | Call[],
|
|
75
|
-
_abisOrDetails?: Abi[] | UniversalDetails,
|
|
76
|
-
_transactionsDetail?: UniversalDetails,
|
|
77
|
-
): Promise<InvokeFunctionResponse> {
|
|
78
|
-
return this.controller.execute(normalizeCalls(calls));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
83
|
-
* This adds a message prefix so it cant be interchanged with transactions
|
|
84
|
-
*
|
|
85
|
-
* @param json - JSON object to be signed
|
|
86
|
-
* @returns the signature of the JSON object
|
|
87
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
88
|
-
*/
|
|
89
|
-
async signMessage(_typedData: TypedData): Promise<Signature> {
|
|
90
|
-
throw new Error("signMessage not implemented for SessionSigner");
|
|
91
|
-
}
|
|
92
|
-
}
|
package/src/signer.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Abi,
|
|
3
|
-
BigNumberish,
|
|
4
|
-
Call,
|
|
5
|
-
DeclareSignerDetails,
|
|
6
|
-
DeployAccountSignerDetails,
|
|
7
|
-
InvocationsSignerDetails,
|
|
8
|
-
Signature,
|
|
9
|
-
SignerInterface,
|
|
10
|
-
TypedData,
|
|
11
|
-
} from "starknet";
|
|
12
|
-
|
|
13
|
-
import { Keychain, Modal } from "./types";
|
|
14
|
-
import { AsyncMethodReturns } from "@cartridge/penpal";
|
|
15
|
-
import { CartridgeSessionAccount } from "@cartridge/account-wasm/session";
|
|
16
|
-
import { normalizeCalls } from "./utils";
|
|
17
|
-
|
|
18
|
-
export class Signer implements SignerInterface {
|
|
19
|
-
private keychain: AsyncMethodReturns<Keychain>;
|
|
20
|
-
modal: Modal;
|
|
21
|
-
constructor(keychain: AsyncMethodReturns<Keychain>, modal: Modal) {
|
|
22
|
-
this.keychain = keychain;
|
|
23
|
-
this.modal = modal;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Method to get the public key of the signer
|
|
28
|
-
*
|
|
29
|
-
* @returns public key of signer as hex string with 0x prefix
|
|
30
|
-
*/
|
|
31
|
-
public getPubKey(): Promise<string> {
|
|
32
|
-
return Promise.resolve("");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
37
|
-
* This adds a message prefix so it cant be interchanged with transactions
|
|
38
|
-
*
|
|
39
|
-
* @param typedData - JSON object to be signed
|
|
40
|
-
* @param accountAddress - account
|
|
41
|
-
* @returns the signature of the JSON object
|
|
42
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
43
|
-
*/
|
|
44
|
-
public async signMessage(
|
|
45
|
-
typedData: TypedData,
|
|
46
|
-
account: string,
|
|
47
|
-
): Promise<Signature> {
|
|
48
|
-
this.modal.open();
|
|
49
|
-
const res = await this.keychain.signMessage(typedData, account);
|
|
50
|
-
this.modal.close();
|
|
51
|
-
return res as Signature;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public async signTransaction(
|
|
55
|
-
transactions: Call[],
|
|
56
|
-
transactionsDetail: InvocationsSignerDetails,
|
|
57
|
-
abis?: Abi[],
|
|
58
|
-
): Promise<Signature> {
|
|
59
|
-
this.modal.open();
|
|
60
|
-
const res = await this.keychain.signTransaction(
|
|
61
|
-
transactions,
|
|
62
|
-
transactionsDetail,
|
|
63
|
-
abis,
|
|
64
|
-
);
|
|
65
|
-
this.modal.close();
|
|
66
|
-
return res;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public async signDeployAccountTransaction(
|
|
70
|
-
transaction: DeployAccountSignerDetails,
|
|
71
|
-
): Promise<Signature> {
|
|
72
|
-
this.modal.open();
|
|
73
|
-
const res = await this.keychain.signDeployAccountTransaction(transaction);
|
|
74
|
-
this.modal.close();
|
|
75
|
-
return res;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public async signDeclareTransaction(
|
|
79
|
-
transaction: DeclareSignerDetails,
|
|
80
|
-
): Promise<Signature> {
|
|
81
|
-
this.modal.open();
|
|
82
|
-
const res = await this.keychain.signDeclareTransaction(transaction);
|
|
83
|
-
this.modal.close();
|
|
84
|
-
return res;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export class SessionSigner implements SignerInterface {
|
|
89
|
-
controller: CartridgeSessionAccount;
|
|
90
|
-
|
|
91
|
-
constructor(controller: CartridgeSessionAccount) {
|
|
92
|
-
this.controller = controller;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Method to get the public key of the signer
|
|
97
|
-
*
|
|
98
|
-
* @returns public key of signer as hex string with 0x prefix
|
|
99
|
-
*/
|
|
100
|
-
public getPubKey(): Promise<string> {
|
|
101
|
-
return Promise.resolve("");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
106
|
-
* This adds a message prefix so it cant be interchanged with transactions
|
|
107
|
-
*
|
|
108
|
-
* @param typedData - JSON object to be signed
|
|
109
|
-
* @param accountAddress - account
|
|
110
|
-
* @returns the signature of the JSON object
|
|
111
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
112
|
-
*/
|
|
113
|
-
public async signMessage(
|
|
114
|
-
_typedData: TypedData,
|
|
115
|
-
_account: string,
|
|
116
|
-
): Promise<Signature> {
|
|
117
|
-
throw new Error("signMessage not implemented for SessionSigner");
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
public async signTransaction(
|
|
121
|
-
transactions: Call[],
|
|
122
|
-
transactionsDetail: InvocationsSignerDetails & { maxFee: BigNumberish },
|
|
123
|
-
_abis?: Abi[],
|
|
124
|
-
): Promise<Signature> {
|
|
125
|
-
return this.controller.sign_transaction(
|
|
126
|
-
normalizeCalls(transactions),
|
|
127
|
-
transactionsDetail.maxFee,
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
public async signDeployAccountTransaction(
|
|
132
|
-
_transaction: DeployAccountSignerDetails,
|
|
133
|
-
): Promise<Signature> {
|
|
134
|
-
throw new Error(
|
|
135
|
-
"signDeployAccountTransaction not implemented for SessionSigner",
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
public async signDeclareTransaction(
|
|
140
|
-
_transaction: DeclareSignerDetails,
|
|
141
|
-
): Promise<Signature> {
|
|
142
|
-
throw new Error("signDeclareTransaction not implemented for SessionSigner");
|
|
143
|
-
}
|
|
144
|
-
}
|