@cartridge/controller 0.3.18 → 0.3.20

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.
Files changed (46) hide show
  1. package/LICENSE +16 -0
  2. package/{lib → dist}/constants.d.ts +1 -7
  3. package/dist/constants.js +25 -0
  4. package/dist/constants.js.map +1 -0
  5. package/{lib → dist}/device.d.ts +3 -3
  6. package/dist/device.js +92 -0
  7. package/dist/device.js.map +1 -0
  8. package/dist/errors.js +9 -0
  9. package/dist/errors.js.map +1 -0
  10. package/{lib → dist}/index.d.ts +12 -12
  11. package/dist/index.js +221 -0
  12. package/dist/index.js.map +1 -0
  13. package/{lib → dist}/inject.d.ts +13 -12
  14. package/{lib → dist}/inject.js +15 -51
  15. package/dist/inject.js.map +1 -0
  16. package/{lib → dist}/modal.js +3 -7
  17. package/dist/modal.js.map +1 -0
  18. package/{lib → dist}/signer.d.ts +6 -3
  19. package/dist/signer.js +48 -0
  20. package/dist/signer.js.map +1 -0
  21. package/{lib → dist}/types.d.ts +14 -15
  22. package/dist/types.js +8 -0
  23. package/dist/types.js.map +1 -0
  24. package/dist/utils.d.ts +19 -0
  25. package/dist/utils.js +107 -0
  26. package/dist/utils.js.map +1 -0
  27. package/package.json +17 -21
  28. package/lib/constants.js +0 -35
  29. package/lib/constants.js.map +0 -1
  30. package/lib/device.js +0 -103
  31. package/lib/device.js.map +0 -1
  32. package/lib/errors.js +0 -13
  33. package/lib/errors.js.map +0 -1
  34. package/lib/index.js +0 -278
  35. package/lib/index.js.map +0 -1
  36. package/lib/inject.js.map +0 -1
  37. package/lib/modal.js.map +0 -1
  38. package/lib/signer.js +0 -45
  39. package/lib/signer.js.map +0 -1
  40. package/lib/types.js +0 -16
  41. package/lib/types.js.map +0 -1
  42. package/lib/utils.d.ts +0 -20
  43. package/lib/utils.js +0 -126
  44. package/lib/utils.js.map +0 -1
  45. /package/{lib → dist}/errors.d.ts +0 -0
  46. /package/{lib → dist}/modal.d.ts +0 -0
package/LICENSE ADDED
@@ -0,0 +1,16 @@
1
+ Copyright Cartridge Gaming Company 2022. All rights reserved.
2
+
3
+ You acknowledge and agree that Cartridge Gaming Company (“Cartridge”) (or Cartridge’s licensors) own all legal right, title and interest in and to the work, software, application, source code, documentation and any other documents in this repository (collectively, the “Program”), including any intellectual property rights which subsist in the Program (whether those rights happen to be registered or not, and wherever in the world those rights may exist), whether in source code or any other form.
4
+
5
+ Subject to the limited license below, you may not (and you may not permit anyone else to) distribute, publish, copy, modify, merge, combine with another program, create derivative works of, reverse engineer, decompile or otherwise attempt to extract the source code of, the Program or any part thereof, except that you may contribute to this repository.
6
+
7
+ You are granted a non-exclusive, non-transferable, non-sublicensable license to distribute, publish, copy, modify, merge, combine with another program or create derivative works of the Program (such resulting program, collectively, the “Resulting Program”) solely for Non-Commercial Use as long as you:
8
+ 1. give prominent notice (“Notice”) with each copy of the Resulting Program that the Program is used in the Resulting Program and that the Program is the copyright of Cartridge; and
9
+ 2. subject the Resulting Program and any distribution, publication, copy, modification, merger therewith, combination with another program or derivative works thereof to the same Notice requirement and Non-Commercial Use restriction set forth herein.
10
+
11
+ “Non-Commercial Use” means each use as described in clauses (1)-(3) below, as reasonably determined by Cartridge in its sole discretion:
12
+ 1. personal use for research, personal study, private entertainment, hobby projects or amateur pursuits, in each case without any anticipated commercial application;
13
+ 2. use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization or government institution; or
14
+ 3. the number of monthly active users of the Resulting Program across all versions thereof and platforms globally do not exceed 10,000 at any time.
15
+
16
+ You will not use any trade mark, service mark, trade name, logo of Cartridge or any other company or organization in a way that is likely or intended to cause confusion about the owner or authorized user of such marks, names or logos.
@@ -1,7 +1,5 @@
1
- export declare const GATEWAY_MAINNET = "https://alpha-mainnet.starknet.io/feeder_gateway";
2
- export declare const GATEWAY_GOERLI = "https://alpha4.starknet.io/feeder_gateway";
3
1
  export declare const ETH_RPC_MAINNET = "https://eth-mainnet.g.alchemy.com/v2/OGPRMquXP3K7oTkLrmVZpjCd1DswtYz3";
4
- export declare const ETH_RPC_GOERLI = "https://eth-goerli.g.alchemy.com/v2/RMPbO9CyB-lVmkbpXCyg8W482pZDDht_";
2
+ export declare const ETH_RPC_SEPOLIA = "https://eth-sepolia.g.alchemy.com/v2/mURnclB5pn5elDfyzgTN4W2GR-rOYevI";
5
3
  export declare const CONTRACT_ETH = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
6
4
  export declare const CONTRACT_POINTS = "0x00c62540e9a10c47a4b7d8abaff468192c66f2d1e979f6bade6e44bf73995982";
7
5
  export declare const CONTRACT_AVATAR = "0x002e02ab50ad223a4de99d7591cbbb565705893ad5b8522a9bde011d20e99926";
@@ -23,7 +21,3 @@ export declare const CLASS_HASHES: {
23
21
  legacyController: string;
24
22
  };
25
23
  };
26
- export declare const NamedChainId: {
27
- "0x534e5f4d41494e": string;
28
- "0x534e5f474f45524c49": string;
29
- };
@@ -0,0 +1,25 @@
1
+ export const ETH_RPC_MAINNET = "https://eth-mainnet.g.alchemy.com/v2/OGPRMquXP3K7oTkLrmVZpjCd1DswtYz3";
2
+ export const ETH_RPC_SEPOLIA = "https://eth-sepolia.g.alchemy.com/v2/mURnclB5pn5elDfyzgTN4W2GR-rOYevI";
3
+ export const CONTRACT_ETH = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
4
+ export const CONTRACT_POINTS = "0x00c62540e9a10c47a4b7d8abaff468192c66f2d1e979f6bade6e44bf73995982";
5
+ export const CONTRACT_AVATAR = "0x002e02ab50ad223a4de99d7591cbbb565705893ad5b8522a9bde011d20e99926";
6
+ export const CONTRACT_CONTROLLER_CLASS = "0x077007d85dd2466b2b29e626bac27ee017d7586f62511f4585dd596f33337ccf";
7
+ export const CONTRACT_ARGENT_CLASS = "0x025ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918";
8
+ export const CONTRACT_ACHIEVEMENTS = "0x00f6883b55c1ed7814e5df15fa8fa4bdbad4d4778662a62413c1e58fce10f4f0";
9
+ export const CONTRACT_UPGRADE_IMPLEMENTATION = "0x07e28fb0161d10d1cf7fe1f13e7ca57bce062731a3bd04494dfd2d0412699727";
10
+ // L1 Contract
11
+ export const CONTRACT_NFF_BRIDGE = "0xbd701502203B21307BEa2d4078E69dd0c9C0703C";
12
+ export const PROXY_CLASS = "0x04be79b3904b4e2775fd706fa037610b41d8f8708ce298aac3a470badf68176d";
13
+ export const CLASS_HASHES = {
14
+ ["0.0.1"]: {
15
+ account: "0x079507b6068846a05500331e0b54f7b539f067c2003de1f4635fc9885a267144",
16
+ controller: "0x0286a2ea79ee08506efcbc330efd2ae34e2f22b79ecd2fb9b86ce26d6a1dbece",
17
+ legacyController: "0x58e648a242085d5ff1e8f92a6b91057826639a82b23798998d40b61a27bca85",
18
+ },
19
+ ["latest"]: {
20
+ account: "0x627850d612539b1258f64f8d76b0392944bb2886ed891b93e2bff9223317a91",
21
+ controller: "0x6bcb2ecc68f478bd0546c451a0820ce19e2d562e3cfcb5906eede15aa81cc42",
22
+ legacyController: "0x58e648a242085d5ff1e8f92a6b91057826639a82b23798998d40b61a27bca85",
23
+ },
24
+ };
25
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAC1B,uEAAuE,CAAC;AAC1E,MAAM,CAAC,MAAM,eAAe,GAC1B,uEAAuE,CAAA;AAEzE,MAAM,CAAC,MAAM,YAAY,GACvB,oEAAoE,CAAC;AACvE,MAAM,CAAC,MAAM,eAAe,GAC1B,oEAAoE,CAAC;AACvE,MAAM,CAAC,MAAM,eAAe,GAC1B,oEAAoE,CAAC;AAEvE,MAAM,CAAC,MAAM,yBAAyB,GACpC,oEAAoE,CAAC;AACvE,MAAM,CAAC,MAAM,qBAAqB,GAChC,oEAAoE,CAAC;AACvE,MAAM,CAAC,MAAM,qBAAqB,GAChC,oEAAoE,CAAC;AACvE,MAAM,CAAC,MAAM,+BAA+B,GAC1C,oEAAoE,CAAC;AAEvE,cAAc;AACd,MAAM,CAAC,MAAM,mBAAmB,GAAG,4CAA4C,CAAC;AAEhF,MAAM,CAAC,MAAM,WAAW,GACtB,oEAAoE,CAAC;AAEvE,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,CAAC,OAAO,CAAC,EAAE;QACT,OAAO,EACL,oEAAoE;QACtE,UAAU,EACR,oEAAoE;QACtE,gBAAgB,EACd,mEAAmE;KACtE;IACD,CAAC,QAAQ,CAAC,EAAE;QACV,OAAO,EACL,mEAAmE;QACrE,UAAU,EACR,mEAAmE;QACrE,gBAAgB,EACd,mEAAmE;KACtE;CACF,CAAC"}
@@ -1,11 +1,11 @@
1
- import { constants, Account, Abi, Call, EstimateFeeDetails, InvocationsDetails, Signature, typedData, InvokeFunctionResponse, EstimateFee, DeclareContractPayload, SequencerProvider } from "starknet";
1
+ import { Account, Abi, Call, EstimateFeeDetails, Signature, InvokeFunctionResponse, EstimateFee, DeclareContractPayload, RpcProvider, TypedData, InvocationsDetails, constants } from "starknet";
2
2
  import { Keychain, Modal } from "./types";
3
3
  import { AsyncMethodReturns } from "@cartridge/penpal";
4
4
  declare class DeviceAccount extends Account {
5
5
  address: string;
6
6
  private keychain;
7
7
  private modal;
8
- constructor(provider: SequencerProvider, address: string, keychain: AsyncMethodReturns<Keychain>, modal: Modal);
8
+ constructor(provider: RpcProvider, address: string, keychain: AsyncMethodReturns<Keychain>, modal: Modal);
9
9
  /**
10
10
  * Estimate Fee for a method on starknet
11
11
  *
@@ -42,6 +42,6 @@ declare class DeviceAccount extends Account {
42
42
  * @returns the signature of the JSON object
43
43
  * @throws {Error} if the JSON object is not a valid JSON
44
44
  */
45
- signMessage(typedData: typedData.TypedData): Promise<Signature>;
45
+ signMessage(typedData: TypedData): Promise<Signature>;
46
46
  }
47
47
  export default DeviceAccount;
package/dist/device.js ADDED
@@ -0,0 +1,92 @@
1
+ import { Account, } from "starknet";
2
+ import { ResponseCodes } from "./types";
3
+ import { Signer } from "./signer";
4
+ class DeviceAccount extends Account {
5
+ constructor(provider, address, keychain, modal) {
6
+ super(provider, address, new Signer(keychain, modal));
7
+ this.address = address;
8
+ this.keychain = keychain;
9
+ this.modal = modal;
10
+ }
11
+ /**
12
+ * Estimate Fee for a method on starknet
13
+ *
14
+ * @param calls the invocation object containing:
15
+ * - contractAddress - the address of the contract
16
+ * - entrypoint - the entrypoint of the contract
17
+ * - calldata - (defaults to []) the calldata
18
+ * - signature - (defaults to []) the signature
19
+ *
20
+ * @returns response from addTransaction
21
+ */
22
+ async estimateInvokeFee(calls, details) {
23
+ return this.keychain.estimateInvokeFee(calls, {
24
+ ...details,
25
+ chainId: await this.getChainId(),
26
+ });
27
+ }
28
+ async estimateDeclareFee(payload, details) {
29
+ return this.keychain.estimateDeclareFee(payload, {
30
+ ...details,
31
+ chainId: await this.getChainId(),
32
+ });
33
+ }
34
+ /**
35
+ * Invoke execute function in account contract
36
+ *
37
+ * @param calls the invocation object or an array of them, containing:
38
+ * - contractAddress - the address of the contract
39
+ * - entrypoint - the entrypoint of the contract
40
+ * - calldata - (defaults to []) the calldata
41
+ * - signature - (defaults to []) the signature
42
+ * @param abis (optional) the abi of the contract for better displaying
43
+ *
44
+ * @returns response from addTransaction
45
+ */
46
+ // @ts-expect-error TODO: fix overload type mismatch
47
+ async execute(calls, abis, transactionsDetail) {
48
+ if (!transactionsDetail) {
49
+ transactionsDetail = {};
50
+ }
51
+ try {
52
+ const res = await this.keychain.execute(calls, abis, transactionsDetail);
53
+ if (res.code === ResponseCodes.SUCCESS) {
54
+ return res;
55
+ }
56
+ this.modal.open();
57
+ const res2 = await this.keychain.execute(calls, abis, transactionsDetail, true);
58
+ this.modal.close();
59
+ if (res2.code !== ResponseCodes.SUCCESS &&
60
+ res2.code !== ResponseCodes.CANCELED) {
61
+ throw new Error(res2.message);
62
+ }
63
+ return res2;
64
+ }
65
+ catch (e) {
66
+ console.error(e);
67
+ throw e;
68
+ }
69
+ }
70
+ /**
71
+ * Sign an JSON object for off-chain usage with the starknet private key and return the signature
72
+ * This adds a message prefix so it cant be interchanged with transactions
73
+ *
74
+ * @param json - JSON object to be signed
75
+ * @returns the signature of the JSON object
76
+ * @throws {Error} if the JSON object is not a valid JSON
77
+ */
78
+ async signMessage(typedData) {
79
+ try {
80
+ this.modal.open();
81
+ const res = await this.keychain.signMessage(typedData, this.address);
82
+ this.modal.close();
83
+ return res;
84
+ }
85
+ catch (e) {
86
+ console.error(e);
87
+ throw e;
88
+ }
89
+ }
90
+ }
91
+ export default DeviceAccount;
92
+ //# sourceMappingURL=device.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device.js","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,GAYR,MAAM,UAAU,CAAC;AAElB,OAAO,EAAY,aAAa,EAAS,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,MAAM,aAAc,SAAQ,OAAO;IAKjC,YACE,QAAqB,EACrB,OAAe,EACf,QAAsC,EACtC,KAAY;QAEZ,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;QACtD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,iBAAiB,CACrB,KAAoB,EACpB,OAA4B;QAE5B,OAAO,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,KAAK,EAAE;YAC5C,GAAG,OAAO;YACV,OAAO,EAAE,MAAM,IAAI,CAAC,UAAU,EAAE;SACjC,CAAC,CAAC;IACL,CAA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CAAC,SAAoB;QACpC,IAAI,CAAC;YACH,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAClB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACrE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACnB,OAAO,GAAgB,CAAC;QAC1B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACjB,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;CACF;AAED,eAAe,aAAa,CAAC"}
package/dist/errors.js ADDED
@@ -0,0 +1,9 @@
1
+ export class MissingPolicys extends Error {
2
+ constructor(missing) {
3
+ super("missing policies");
4
+ this.missing = missing;
5
+ // because we are extending a built-in class
6
+ Object.setPrototypeOf(this, MissingPolicys.prototype);
7
+ }
8
+ }
9
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,cAAe,SAAQ,KAAK;IAGvC,YAAY,OAAiB;QAC3B,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAE1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,4CAA4C;QAC5C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;IACxD,CAAC;CACF"}
@@ -1,30 +1,28 @@
1
1
  /// <reference types="node" />
2
- import { AccountInterface, constants, SequencerProvider } from "starknet";
2
+ import { AccountInterface, constants, RpcProvider } from "starknet";
3
3
  import { AsyncMethodReturns } from "@cartridge/penpal";
4
- import { Session, Keychain, Policy, SupportedChainIds } from "./types";
4
+ import { Session, Keychain, Policy } from "./types";
5
5
  export declare const providers: {
6
- "0x534e5f474f45524c49": SequencerProvider;
7
- "0x534e5f4d41494e": SequencerProvider;
6
+ [key: string]: RpcProvider;
8
7
  };
9
8
  declare class Controller {
10
9
  private connection?;
11
10
  keychain?: AsyncMethodReturns<Keychain>;
12
11
  private policies;
13
12
  private url;
14
- chainId: SupportedChainIds;
13
+ chainId: constants.StarknetChainId;
15
14
  accounts?: {
16
- [key in SupportedChainIds]: AccountInterface;
15
+ [key: string]: AccountInterface;
17
16
  };
18
17
  private modal?;
19
- private starterPackId?;
20
18
  constructor(policies?: Policy[], options?: {
21
19
  url?: string;
22
20
  origin?: string;
23
21
  starterPackId?: string;
24
- chainId?: SupportedChainIds;
22
+ chainId?: constants.StarknetChainId;
25
23
  });
26
24
  get account(): AccountInterface | undefined;
27
- ready(): Promise<boolean | undefined>;
25
+ ready(): Promise<boolean>;
28
26
  probe(): Promise<true | null | undefined>;
29
27
  switchChain(chainId: constants.StarknetChainId): Promise<void>;
30
28
  register(username: string, credentialId: string, credential: {
@@ -41,11 +39,13 @@ declare class Controller {
41
39
  assertion: import("./types").Assertion;
42
40
  } | null>;
43
41
  provision(address: string, credentialId: string): Promise<string | null>;
44
- issueStarterPack(id: string): Promise<import("starknet").InvokeFunctionResponse | undefined>;
42
+ issueStarterPack(id: string): Promise<{
43
+ transaction_hash: string;
44
+ }>;
45
45
  showQuests(gameId: string): Promise<void>;
46
46
  connect(): Promise<AccountInterface | undefined>;
47
- disconnect(): Promise<void | null>;
48
- revoke(origin: string, policy: Policy[]): Promise<void> | null;
47
+ disconnect(): Promise<void>;
48
+ revoke(origin: string, _policy: Policy[]): Promise<void> | null;
49
49
  approvals(origin: string): Promise<Session | undefined>;
50
50
  }
51
51
  export * from "./types";
package/dist/index.js ADDED
@@ -0,0 +1,221 @@
1
+ import { constants, RpcProvider } from "starknet";
2
+ import { connectToChild, } from "@cartridge/penpal";
3
+ import DeviceAccount from "./device";
4
+ import { ResponseCodes, } from "./types";
5
+ import { createModal } from "./modal";
6
+ export const providers = {
7
+ [constants.StarknetChainId.SN_MAIN]: new RpcProvider({
8
+ nodeUrl: process.env.NEXT_PUBLIC_RPC_MAINNET,
9
+ }),
10
+ [constants.StarknetChainId.SN_SEPOLIA]: new RpcProvider({
11
+ nodeUrl: process.env.NEXT_PUBLIC_RPC_SEPOLIA,
12
+ }),
13
+ };
14
+ class Controller {
15
+ // private starterPackId?: string;
16
+ constructor(policies, options) {
17
+ this.policies = [];
18
+ this.url = "https://x.cartridge.gg";
19
+ this.chainId = constants.StarknetChainId.SN_SEPOLIA;
20
+ if (policies) {
21
+ this.policies = policies;
22
+ }
23
+ if (options?.chainId) {
24
+ this.chainId = options.chainId;
25
+ }
26
+ // if (options?.starterPackId) {
27
+ // this.starterPackId = options.starterPackId;
28
+ // }
29
+ if (options?.url) {
30
+ this.url = options.url;
31
+ }
32
+ if (typeof document === "undefined") {
33
+ return;
34
+ }
35
+ this.modal = createModal(this.url, () => {
36
+ this.keychain?.reset();
37
+ });
38
+ if (document.readyState === "complete" ||
39
+ document.readyState === "interactive") {
40
+ document.body.appendChild(this.modal.element);
41
+ }
42
+ else {
43
+ document.addEventListener("DOMContentLoaded", () => {
44
+ document.body.appendChild(this.modal.element);
45
+ });
46
+ }
47
+ this.connection = connectToChild({
48
+ iframe: this.modal.element.children[0],
49
+ });
50
+ this.connection.promise
51
+ .then((keychain) => (this.keychain = keychain))
52
+ .then(() => this.probe());
53
+ }
54
+ get account() {
55
+ if (!this.accounts) {
56
+ return;
57
+ }
58
+ return this.accounts[this.chainId];
59
+ }
60
+ ready() {
61
+ return (this.connection?.promise
62
+ .then(() => this.probe())
63
+ .then((res) => !!res, () => false) ?? Promise.resolve(false));
64
+ }
65
+ async probe() {
66
+ if (!this.keychain || !this.modal) {
67
+ console.error("not ready for connect");
68
+ return null;
69
+ }
70
+ try {
71
+ const res = await this.keychain.probe();
72
+ if (res.code !== ResponseCodes.SUCCESS) {
73
+ return;
74
+ }
75
+ const { address } = res;
76
+ this.accounts = {
77
+ [constants.StarknetChainId.SN_MAIN]: new DeviceAccount(providers[constants.StarknetChainId.SN_MAIN], address, this.keychain, this.modal), // Note: workaround for execute type mismatch error
78
+ [constants.StarknetChainId.SN_SEPOLIA]: new DeviceAccount(providers[constants.StarknetChainId.SN_SEPOLIA], address, this.keychain, this.modal),
79
+ };
80
+ }
81
+ catch (e) {
82
+ console.error(e);
83
+ return;
84
+ }
85
+ return !!this.accounts?.[this.chainId];
86
+ }
87
+ async switchChain(chainId) {
88
+ if (this.chainId === chainId) {
89
+ return;
90
+ }
91
+ this.chainId = chainId;
92
+ }
93
+ // Register a new device key.
94
+ async register(username, credentialId, credential) {
95
+ if (!this.keychain) {
96
+ console.error("not ready for connect");
97
+ return null;
98
+ }
99
+ return await this.keychain.register(username, credentialId, credential);
100
+ }
101
+ async login(address, credentialId, options) {
102
+ if (!this.keychain) {
103
+ console.error("not ready for connect");
104
+ return null;
105
+ }
106
+ return this.keychain.login(address, credentialId, options);
107
+ }
108
+ async provision(address, credentialId) {
109
+ if (!this.keychain) {
110
+ console.error("not ready for connect");
111
+ return null;
112
+ }
113
+ return this.keychain.provision(address, credentialId);
114
+ }
115
+ async issueStarterPack(id) {
116
+ if (!this.keychain || !this.modal) {
117
+ console.error("not ready for connect");
118
+ return Promise.reject("not ready for connect");
119
+ }
120
+ this.modal.open();
121
+ try {
122
+ if (!this.account) {
123
+ let response = await this.keychain.connect(this.policies, undefined, this.chainId);
124
+ if (response.code !== ResponseCodes.SUCCESS) {
125
+ throw new Error(response.message);
126
+ }
127
+ }
128
+ return await this.keychain.issueStarterPack(id);
129
+ }
130
+ catch (e) {
131
+ console.log(e);
132
+ return Promise.reject(e);
133
+ }
134
+ finally {
135
+ this.modal.close();
136
+ }
137
+ }
138
+ async showQuests(gameId) {
139
+ if (!this.keychain || !this.modal) {
140
+ console.error("not ready for connect");
141
+ return;
142
+ }
143
+ this.modal.open();
144
+ try {
145
+ return await this.keychain.showQuests(gameId);
146
+ }
147
+ catch (e) {
148
+ console.error(e);
149
+ }
150
+ finally {
151
+ this.modal.close();
152
+ }
153
+ }
154
+ async connect() {
155
+ if (this.accounts) {
156
+ return this.accounts[this.chainId];
157
+ }
158
+ if (!this.keychain || !this.modal) {
159
+ console.error("not ready for connect");
160
+ return;
161
+ }
162
+ if (!!document.hasStorageAccess) {
163
+ const ok = await document.hasStorageAccess();
164
+ if (!ok) {
165
+ await document.requestStorageAccess();
166
+ }
167
+ }
168
+ this.modal.open();
169
+ try {
170
+ let response = await this.keychain.connect(this.policies, undefined, this.chainId);
171
+ if (response.code !== ResponseCodes.SUCCESS) {
172
+ throw new Error(response.message);
173
+ }
174
+ response = response;
175
+ this.accounts = {
176
+ [constants.StarknetChainId.SN_MAIN]: new DeviceAccount(providers[constants.StarknetChainId.SN_MAIN], response.address, this.keychain, this.modal),
177
+ [constants.StarknetChainId.SN_SEPOLIA]: new DeviceAccount(providers[constants.StarknetChainId.SN_SEPOLIA], response.address, this.keychain, this.modal),
178
+ };
179
+ return this.accounts[this.chainId];
180
+ }
181
+ catch (e) {
182
+ console.log(e);
183
+ }
184
+ finally {
185
+ this.modal.close();
186
+ }
187
+ }
188
+ async disconnect() {
189
+ if (!this.keychain) {
190
+ console.error("not ready for disconnect");
191
+ return;
192
+ }
193
+ if (!!document.hasStorageAccess) {
194
+ const ok = await document.hasStorageAccess();
195
+ if (!ok) {
196
+ await document.requestStorageAccess();
197
+ }
198
+ }
199
+ return this.keychain.disconnect();
200
+ }
201
+ revoke(origin, _policy) {
202
+ if (!this.keychain) {
203
+ console.error("not ready for disconnect");
204
+ return null;
205
+ }
206
+ return this.keychain.revoke(origin);
207
+ }
208
+ async approvals(origin) {
209
+ if (!this.keychain) {
210
+ console.error("not ready for disconnect");
211
+ return;
212
+ }
213
+ return this.keychain.approvals(origin);
214
+ }
215
+ }
216
+ export * from "./types";
217
+ export * from "./errors";
218
+ export { computeAddress, split, verifyMessageHash } from "./utils";
219
+ export { injectController } from "./inject";
220
+ export default Controller;
221
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"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AC,CAAC;IACzC,CAAC;CACF;AAED,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,eAAe,UAAU,CAAC"}
@@ -1,7 +1,8 @@
1
+ import { constants } from "starknet";
1
2
  import { AccountInterface, ProviderInterface } from "starknet";
2
- import { Policy, SupportedChainIds } from "./types";
3
- export declare type EventType = "accountsChanged" | "networkChanged";
4
- export declare type EventHandler = (data: any) => void;
3
+ import { Policy } from "./types";
4
+ export type EventType = "accountsChanged" | "networkChanged";
5
+ export type EventHandler = (data: any) => void;
5
6
  interface WatchAssetParameters {
6
7
  type: string;
7
8
  options: {
@@ -12,7 +13,7 @@ interface WatchAssetParameters {
12
13
  name?: string;
13
14
  };
14
15
  }
15
- export declare type RpcMessage = {
16
+ export type RpcMessage = {
16
17
  type: "wallet_watchAsset";
17
18
  params: WatchAssetParameters;
18
19
  result: boolean;
@@ -21,10 +22,10 @@ export declare type RpcMessage = {
21
22
  params: unknown;
22
23
  result: never;
23
24
  };
24
- export declare type AccountChangeEventHandler = (accounts: string[]) => void;
25
- export declare type NetworkChangeEventHandler = (network?: string) => void;
26
- export declare type WalletEventHandlers = AccountChangeEventHandler | NetworkChangeEventHandler;
27
- export declare type WalletEvents = {
25
+ export type AccountChangeEventHandler = (accounts: string[]) => void;
26
+ export type NetworkChangeEventHandler = (network?: string) => void;
27
+ export type WalletEventHandlers = AccountChangeEventHandler | NetworkChangeEventHandler;
28
+ export type WalletEvents = {
28
29
  type: "accountsChanged";
29
30
  handler: AccountChangeEventHandler;
30
31
  } | {
@@ -53,7 +54,7 @@ export declare class InjectedController implements IStarknetWindowObject {
53
54
  name: string;
54
55
  version: string;
55
56
  icon: string;
56
- provider: import("starknet").SequencerProvider;
57
+ provider: import("starknet").Provider;
57
58
  isConnected: boolean;
58
59
  account?: AccountInterface | undefined;
59
60
  selectedAddress?: string;
@@ -63,9 +64,9 @@ export declare class InjectedController implements IStarknetWindowObject {
63
64
  url?: string;
64
65
  origin?: string;
65
66
  starterPackId?: string;
66
- chainId?: SupportedChainIds;
67
+ chainId?: constants.StarknetChainId;
67
68
  });
68
- request: (call: Omit<RpcMessage, "result">) => Promise<RpcMessage["result"]>;
69
+ request: (_call: Omit<RpcMessage, "result">) => Promise<RpcMessage["result"]>;
69
70
  enable: () => Promise<string[]>;
70
71
  isPreauthorized: () => Promise<boolean>;
71
72
  on: (type: EventType, handler: EventHandler) => void;
@@ -75,6 +76,6 @@ declare function injectController(policies?: Policy[], options?: {
75
76
  url?: string;
76
77
  origin?: string;
77
78
  starterPackId?: string;
78
- chainId?: SupportedChainIds;
79
+ chainId?: constants.StarknetChainId;
79
80
  }): void;
80
81
  export { injectController };