@cartridge/controller 0.13.10-alpha.1 → 0.13.10
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 +14 -14
- package/dist/iframe/keychain.d.ts +1 -1
- package/dist/{index-B46sSAxE.js → index-C7KGk-LM.js} +473 -198
- package/dist/index-C7KGk-LM.js.map +1 -0
- package/dist/index.js +783 -769
- package/dist/index.js.map +1 -1
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/session.js +4 -4
- package/dist/stats.html +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/utils.d.ts +0 -1
- package/dist/wallets/ethereum-base.d.ts +5 -1
- package/dist/wallets/metamask/index.d.ts +1 -0
- package/dist/wallets/phantom-evm/index.d.ts +1 -0
- package/package.json +3 -4
- package/src/controller.ts +3 -3
- package/src/iframe/keychain.ts +5 -0
- package/src/types.ts +2 -0
- package/src/utils.ts +0 -8
- package/src/wallets/ethereum-base.ts +35 -48
- package/src/wallets/metamask/index.ts +6 -0
- package/src/wallets/phantom-evm/index.ts +4 -0
- package/dist/index-B46sSAxE.js.map +0 -1
- package/dist/telegram/backend.d.ts +0 -30
- package/dist/telegram/provider.d.ts +0 -24
- package/src/telegram/backend.ts +0 -43
- package/src/telegram/provider.ts +0 -148
package/src/telegram/provider.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
cloudStorage,
|
|
3
|
-
miniApp,
|
|
4
|
-
openLink,
|
|
5
|
-
retrieveLaunchParams,
|
|
6
|
-
} from "@telegram-apps/sdk";
|
|
7
|
-
import { ec, stark, WalletAccount } from "starknet";
|
|
8
|
-
|
|
9
|
-
import { KEYCHAIN_URL } from "../constants";
|
|
10
|
-
import SessionAccount from "../session/account";
|
|
11
|
-
import BaseProvider from "../provider";
|
|
12
|
-
import { toWasmPolicies } from "../utils";
|
|
13
|
-
import { SessionPolicies } from "@cartridge/presets";
|
|
14
|
-
import { AddStarknetChainParameters } from "@starknet-io/types-js";
|
|
15
|
-
import { ParsedSessionPolicies, parsePolicies } from "../policies";
|
|
16
|
-
|
|
17
|
-
interface SessionRegistration {
|
|
18
|
-
username: string;
|
|
19
|
-
address: string;
|
|
20
|
-
ownerGuid: string;
|
|
21
|
-
transactionHash?: string;
|
|
22
|
-
expiresAt: string;
|
|
23
|
-
guardianKeyGuid: string;
|
|
24
|
-
metadataHash: string;
|
|
25
|
-
sessionKeyGuid: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default class TelegramProvider extends BaseProvider {
|
|
29
|
-
private _tmaUrl: string;
|
|
30
|
-
protected _chainId: string;
|
|
31
|
-
protected _username?: string;
|
|
32
|
-
protected _policies: ParsedSessionPolicies;
|
|
33
|
-
private _rpcUrl: string;
|
|
34
|
-
|
|
35
|
-
constructor({
|
|
36
|
-
rpc,
|
|
37
|
-
chainId,
|
|
38
|
-
policies,
|
|
39
|
-
tmaUrl,
|
|
40
|
-
}: {
|
|
41
|
-
rpc: string;
|
|
42
|
-
chainId: string;
|
|
43
|
-
policies: SessionPolicies;
|
|
44
|
-
tmaUrl: string;
|
|
45
|
-
}) {
|
|
46
|
-
super();
|
|
47
|
-
|
|
48
|
-
this._rpcUrl = rpc;
|
|
49
|
-
this._tmaUrl = tmaUrl;
|
|
50
|
-
this._chainId = chainId;
|
|
51
|
-
this._policies = parsePolicies(policies);
|
|
52
|
-
|
|
53
|
-
if (typeof window !== "undefined") {
|
|
54
|
-
(window as any).starknet_controller = this;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async probe(): Promise<WalletAccount | undefined> {
|
|
59
|
-
await this.tryRetrieveFromQueryOrStorage();
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async connect(): Promise<WalletAccount | undefined> {
|
|
64
|
-
await this.tryRetrieveFromQueryOrStorage();
|
|
65
|
-
if (this.account) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Generate a random local key pair
|
|
70
|
-
const pk = stark.randomAddress();
|
|
71
|
-
const publicKey = ec.starkCurve.getStarkKey(pk);
|
|
72
|
-
|
|
73
|
-
cloudStorage.setItem(
|
|
74
|
-
"sessionSigner",
|
|
75
|
-
JSON.stringify({
|
|
76
|
-
privKey: pk,
|
|
77
|
-
pubKey: publicKey,
|
|
78
|
-
}),
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
const url = `${KEYCHAIN_URL}/session?public_key=${publicKey}&redirect_uri=${
|
|
82
|
-
this._tmaUrl
|
|
83
|
-
}&redirect_query_name=startapp&policies=${JSON.stringify(
|
|
84
|
-
this._policies,
|
|
85
|
-
)}&rpc_url=${this._rpcUrl}`;
|
|
86
|
-
|
|
87
|
-
localStorage.setItem("lastUsedConnector", this.id);
|
|
88
|
-
openLink(url);
|
|
89
|
-
miniApp.close();
|
|
90
|
-
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
switchStarknetChain(_chainId: string): Promise<boolean> {
|
|
95
|
-
throw new Error("switchStarknetChain not implemented");
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
addStarknetChain(_chain: AddStarknetChainParameters): Promise<boolean> {
|
|
99
|
-
throw new Error("addStarknetChain not implemented");
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
disconnect(): Promise<void> {
|
|
103
|
-
cloudStorage.deleteItem("sessionSigner");
|
|
104
|
-
cloudStorage.deleteItem("session");
|
|
105
|
-
this.account = undefined;
|
|
106
|
-
this._username = undefined;
|
|
107
|
-
return Promise.resolve();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async tryRetrieveFromQueryOrStorage() {
|
|
111
|
-
const signer = JSON.parse((await cloudStorage.getItem("sessionSigner"))!);
|
|
112
|
-
let sessionRegistration: SessionRegistration | null = null;
|
|
113
|
-
|
|
114
|
-
const launchParams = retrieveLaunchParams();
|
|
115
|
-
const session = launchParams.startParam;
|
|
116
|
-
if (session) {
|
|
117
|
-
sessionRegistration = JSON.parse(atob(session));
|
|
118
|
-
cloudStorage.setItem("session", JSON.stringify(sessionRegistration));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (!sessionRegistration) {
|
|
122
|
-
const session = await cloudStorage.getItem("session");
|
|
123
|
-
if (session) {
|
|
124
|
-
sessionRegistration = JSON.parse(session);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (!sessionRegistration) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
this._username = sessionRegistration.username;
|
|
133
|
-
this.account = new SessionAccount(this, {
|
|
134
|
-
rpcUrl: this._rpcUrl,
|
|
135
|
-
privateKey: signer.privKey,
|
|
136
|
-
address: sessionRegistration.address,
|
|
137
|
-
ownerGuid: sessionRegistration.ownerGuid,
|
|
138
|
-
chainId: this._chainId,
|
|
139
|
-
expiresAt: parseInt(sessionRegistration.expiresAt),
|
|
140
|
-
policies: toWasmPolicies(this._policies),
|
|
141
|
-
guardianKeyGuid: sessionRegistration.guardianKeyGuid,
|
|
142
|
-
metadataHash: sessionRegistration.metadataHash,
|
|
143
|
-
sessionKeyGuid: sessionRegistration.sessionKeyGuid,
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
return this.account;
|
|
147
|
-
}
|
|
148
|
-
}
|