@cartridge/controller 0.2.18 → 0.3.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/lib/account.d.ts +57 -0
- package/lib/account.js +145 -0
- package/lib/account.js.map +1 -0
- package/lib/device.d.ts +3 -7
- package/lib/device.js +23 -25
- package/lib/device.js.map +1 -1
- package/lib/errors.d.ts +5 -0
- package/lib/index.d.ts +8 -8
- package/lib/index.js +79 -56
- package/lib/index.js.map +1 -1
- package/lib/messenger.js +74 -0
- package/lib/messenger.js.map +1 -0
- package/lib/signer.d.ts +24 -0
- package/lib/signer.js +6 -14
- package/lib/signer.js.map +1 -1
- package/lib/types.d.ts +33 -15
- package/lib/types.js +8 -0
- package/lib/types.js.map +1 -1
- package/lib/utils.d.ts +2 -0
- package/lib/webauthn.d.ts +24 -0
- package/lib/webauthn.js +153 -0
- package/lib/webauthn.js.map +1 -0
- package/package.json +2 -1
- package/lib/modal.d.ts +0 -8
- package/lib/modal.js +0 -59
- package/lib/modal.js.map +0 -1
package/lib/account.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Account, DeployContractPayload, Abi, Call, EstimateFeeDetails, DeployContractResponse as StarknetDeployContractResponse, InvocationsDetails, Signature, typedData, InvokeFunctionResponse, EstimateFee } from "starknet";
|
|
2
|
+
import { Scope, Keychain } from "./types";
|
|
3
|
+
import { AsyncMethodReturns } from "@cartridge/penpal";
|
|
4
|
+
declare class CartridgeAccount extends Account {
|
|
5
|
+
address: string;
|
|
6
|
+
private keychain;
|
|
7
|
+
private url;
|
|
8
|
+
constructor(address: string, scopes: Scope[] | undefined, keychain: AsyncMethodReturns<Keychain>, options?: {
|
|
9
|
+
url?: string;
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Deploys a given compiled contract (json) to starknet
|
|
13
|
+
*
|
|
14
|
+
* @param payload payload to be deployed containing:
|
|
15
|
+
* - compiled contract code
|
|
16
|
+
* - constructor calldata
|
|
17
|
+
* - address salt
|
|
18
|
+
* @param abi the abi of the contract
|
|
19
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
20
|
+
*/
|
|
21
|
+
deployContract(payload: DeployContractPayload, abi?: Abi): Promise<StarknetDeployContractResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Estimate Fee for a method on starknet
|
|
24
|
+
*
|
|
25
|
+
* @param calls the invocation object containing:
|
|
26
|
+
* - contractAddress - the address of the contract
|
|
27
|
+
* - entrypoint - the entrypoint of the contract
|
|
28
|
+
* - calldata - (defaults to []) the calldata
|
|
29
|
+
* - signature - (defaults to []) the signature
|
|
30
|
+
*
|
|
31
|
+
* @returns response from addTransaction
|
|
32
|
+
*/
|
|
33
|
+
estimateFee(calls: Call | Call[], details?: EstimateFeeDetails): Promise<EstimateFee>;
|
|
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
|
+
execute(calls: Call | Call[], abis?: Abi[], transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
47
|
+
/**
|
|
48
|
+
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
49
|
+
* This adds a message prefix so it cant be interchanged with transactions
|
|
50
|
+
*
|
|
51
|
+
* @param json - JSON object to be signed
|
|
52
|
+
* @returns the signature of the JSON object
|
|
53
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
54
|
+
*/
|
|
55
|
+
signMessage(typedData: typedData.TypedData): Promise<Signature>;
|
|
56
|
+
}
|
|
57
|
+
export default CartridgeAccount;
|
package/lib/account.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const cuid_1 = __importDefault(require("cuid"));
|
|
16
|
+
const starknet_1 = require("starknet");
|
|
17
|
+
const query_string_1 = __importDefault(require("query-string"));
|
|
18
|
+
const signer_1 = require("./signer");
|
|
19
|
+
const constants_1 = require("starknet/constants");
|
|
20
|
+
class CartridgeAccount extends starknet_1.Account {
|
|
21
|
+
constructor(address, scopes = [], keychain, options) {
|
|
22
|
+
super(starknet_1.defaultProvider, address, new signer_1.Signer(keychain, options));
|
|
23
|
+
this.url = "https://x.cartridge.gg";
|
|
24
|
+
this.address = address;
|
|
25
|
+
this.keychain = keychain;
|
|
26
|
+
if (options === null || options === void 0 ? void 0 : options.url) {
|
|
27
|
+
this.url = options.url;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Deploys a given compiled contract (json) to starknet
|
|
32
|
+
*
|
|
33
|
+
* @param payload payload to be deployed containing:
|
|
34
|
+
* - compiled contract code
|
|
35
|
+
* - constructor calldata
|
|
36
|
+
* - address salt
|
|
37
|
+
* @param abi the abi of the contract
|
|
38
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
39
|
+
*/
|
|
40
|
+
deployContract(payload, abi) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const id = (0, cuid_1.default)();
|
|
43
|
+
window.open(`${this.url}/deploy?origin=${encodeURIComponent(window.origin)}&id=${id}`, "_blank", "height=650,width=400");
|
|
44
|
+
throw new Error("unimplemented");
|
|
45
|
+
// const response = await this.messenger.send<DeployContractResponse>({
|
|
46
|
+
// method: "deploy-contract",
|
|
47
|
+
// params: {
|
|
48
|
+
// id,
|
|
49
|
+
// payload,
|
|
50
|
+
// abi,
|
|
51
|
+
// },
|
|
52
|
+
// });
|
|
53
|
+
// if (response.error) {
|
|
54
|
+
// throw new Error(response.error as string);
|
|
55
|
+
// }
|
|
56
|
+
// return response.result!;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Estimate Fee for a method on starknet
|
|
61
|
+
*
|
|
62
|
+
* @param calls the invocation object containing:
|
|
63
|
+
* - contractAddress - the address of the contract
|
|
64
|
+
* - entrypoint - the entrypoint of the contract
|
|
65
|
+
* - calldata - (defaults to []) the calldata
|
|
66
|
+
* - signature - (defaults to []) the signature
|
|
67
|
+
*
|
|
68
|
+
* @returns response from addTransaction
|
|
69
|
+
*/
|
|
70
|
+
estimateFee(calls, details) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
return this.keychain.estimateFee(calls, details);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Invoke execute function in account contract
|
|
77
|
+
*
|
|
78
|
+
* @param calls the invocation object or an array of them, containing:
|
|
79
|
+
* - contractAddress - the address of the contract
|
|
80
|
+
* - entrypoint - the entrypoint of the contract
|
|
81
|
+
* - calldata - (defaults to []) the calldata
|
|
82
|
+
* - signature - (defaults to []) the signature
|
|
83
|
+
* @param abis (optional) the abi of the contract for better displaying
|
|
84
|
+
*
|
|
85
|
+
* @returns response from addTransaction
|
|
86
|
+
*/
|
|
87
|
+
execute(calls, abis, transactionsDetail) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
if (!transactionsDetail) {
|
|
90
|
+
transactionsDetail = {};
|
|
91
|
+
}
|
|
92
|
+
if (!transactionsDetail.nonce) {
|
|
93
|
+
transactionsDetail.nonce = 0; //await this.getNonce();
|
|
94
|
+
}
|
|
95
|
+
if (!transactionsDetail.version) {
|
|
96
|
+
transactionsDetail.version = 1;
|
|
97
|
+
}
|
|
98
|
+
if (!transactionsDetail.maxFee) {
|
|
99
|
+
try {
|
|
100
|
+
transactionsDetail.maxFee = "100"; // (await this.estimateFee(calls, { nonce: transactionsDetail.nonce })).suggestedMaxFee
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
console.error(e);
|
|
104
|
+
throw e;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
return yield this.keychain.execute(calls, abis, transactionsDetail);
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
if (e.message !== "missing scopes") {
|
|
112
|
+
console.error(e);
|
|
113
|
+
throw e;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
window.open(`${this.url}/execute?${query_string_1.default.stringify({
|
|
117
|
+
origin: window.origin,
|
|
118
|
+
calls: JSON.stringify(calls),
|
|
119
|
+
nonce: transactionsDetail.nonce,
|
|
120
|
+
version: transactionsDetail.version,
|
|
121
|
+
maxFee: transactionsDetail.maxFee,
|
|
122
|
+
chainId: constants_1.StarknetChainId.TESTNET,
|
|
123
|
+
})}`, "_blank", "height=650,width=400");
|
|
124
|
+
return this.keychain.execute(calls, abis, transactionsDetail, true);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
129
|
+
* This adds a message prefix so it cant be interchanged with transactions
|
|
130
|
+
*
|
|
131
|
+
* @param json - JSON object to be signed
|
|
132
|
+
* @returns the signature of the JSON object
|
|
133
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
134
|
+
*/
|
|
135
|
+
signMessage(typedData) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
window.open(`${this.url}/sign?${query_string_1.default.stringify({
|
|
138
|
+
typedData: JSON.stringify(typedData),
|
|
139
|
+
})}`, "_blank", "height=650,width=400");
|
|
140
|
+
return this.keychain.signMessage(typedData, this.address);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.default = CartridgeAccount;
|
|
145
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,uCAakB;AAClB,gEAA8B;AAM9B,qCAAkC;AAElC,kDAAqD;AAErD,MAAM,gBAAiB,SAAQ,kBAAO;IAKpC,YACE,OAAe,EACf,SAAkB,EAAE,EACpB,QAAsC,EACtC,OAEC;QAED,KAAK,CAAC,0BAAe,EAAE,OAAO,EAAE,IAAI,eAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;QAVzD,QAAG,GAAW,wBAAwB,CAAC;QAW7C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,EAAE;YAChB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;SACxB;IACH,CAAC;IAED;;;;;;;;;OASG;IACG,cAAc,CAClB,OAA8B,EAC9B,GAAS;;YAET,MAAM,EAAE,GAAG,IAAA,cAAI,GAAE,CAAC;YAElB,MAAM,CAAC,IAAI,CACT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EAAE;gBACV,IAAK,CAAW,CAAC,OAAO,KAAK,gBAAgB,EAAE;oBAC7C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;oBAChB,MAAM,CAAC,CAAA;iBACR;aACF;YAED,MAAM,CAAC,IAAI,CACT,GAAG,IAAI,CAAC,GAAG,YAAY,sBAAE,CAAC,SAAS,CAAC;gBAClC,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;gBAC5B,KAAK,EAAE,kBAAkB,CAAC,KAAK;gBAC/B,OAAO,EAAE,kBAAkB,CAAC,OAAO;gBACnC,MAAM,EAAE,kBAAkB,CAAC,MAAM;gBACjC,OAAO,EAAE,2BAAe,CAAC,OAAO;aACjC,CAAC,EAAE,EACJ,QAAQ,EACR,sBAAsB,CACvB,CAAC;YAEF,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI,CAAC,CAAC;QACtE,CAAC;KAAA;IAED;;;;;;;OAOG;IACG,WAAW,CAAC,SAA8B;;YAC9C,MAAM,CAAC,IAAI,CACT,GAAG,IAAI,CAAC,GAAG,SAAS,sBAAE,CAAC,SAAS,CAAC;gBAC/B,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;aACrC,CAAC,EAAE,EACJ,QAAQ,EACR,sBAAsB,CACvB,CAAC;YAEF,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5D,CAAC;KAAA;CACF;AAED,kBAAe,gBAAgB,CAAC"}
|
package/lib/device.d.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { constants, Account, Abi, Call, EstimateFeeDetails, InvocationsDetails, Signature, typedData, InvokeFunctionResponse, EstimateFee, DeclareContractPayload, RpcProvider } from "starknet";
|
|
2
|
-
import { Keychain } from "./types";
|
|
2
|
+
import { Keychain, Modal } from "./types";
|
|
3
3
|
import { AsyncMethodReturns } from "@cartridge/penpal";
|
|
4
|
-
import { Modal } from "./modal";
|
|
5
4
|
declare class DeviceAccount extends Account {
|
|
6
5
|
address: string;
|
|
7
6
|
private keychain;
|
|
8
|
-
private
|
|
9
|
-
|
|
10
|
-
constructor(provider: RpcProvider, address: string, keychain: AsyncMethodReturns<Keychain>, modal?: Modal, options?: {
|
|
11
|
-
url?: string;
|
|
12
|
-
});
|
|
7
|
+
private modal;
|
|
8
|
+
constructor(provider: RpcProvider, address: string, keychain: AsyncMethodReturns<Keychain>, modal: Modal);
|
|
13
9
|
/**
|
|
14
10
|
* Estimate Fee for a method on starknet
|
|
15
11
|
*
|
package/lib/device.js
CHANGED
|
@@ -8,23 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
const starknet_1 = require("starknet");
|
|
16
|
-
const
|
|
13
|
+
const types_1 = require("./types");
|
|
17
14
|
const signer_1 = require("./signer");
|
|
18
15
|
class DeviceAccount extends starknet_1.Account {
|
|
19
|
-
constructor(provider, address, keychain, modal
|
|
20
|
-
super(provider, address, new signer_1.Signer(keychain,
|
|
21
|
-
this.url = "https://x.cartridge.gg";
|
|
16
|
+
constructor(provider, address, keychain, modal) {
|
|
17
|
+
super(provider, address, new signer_1.Signer(keychain, modal));
|
|
22
18
|
this.address = address;
|
|
23
19
|
this.keychain = keychain;
|
|
24
20
|
this.modal = modal;
|
|
25
|
-
if (options === null || options === void 0 ? void 0 : options.url) {
|
|
26
|
-
this.url = options.url;
|
|
27
|
-
}
|
|
28
21
|
}
|
|
29
22
|
/**
|
|
30
23
|
* Estimate Fee for a method on starknet
|
|
@@ -60,24 +53,24 @@ class DeviceAccount extends starknet_1.Account {
|
|
|
60
53
|
* @returns response from addTransaction
|
|
61
54
|
*/
|
|
62
55
|
execute(calls, abis, transactionsDetail) {
|
|
63
|
-
var _a;
|
|
64
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
57
|
if (!transactionsDetail) {
|
|
66
58
|
transactionsDetail = {};
|
|
67
59
|
}
|
|
68
60
|
try {
|
|
69
|
-
|
|
61
|
+
const res = yield this.keychain.execute(calls, abis, transactionsDetail);
|
|
62
|
+
if (res.code === types_1.ResponseCodes.SUCCESS) {
|
|
63
|
+
return res;
|
|
64
|
+
}
|
|
65
|
+
this.modal.open();
|
|
66
|
+
const res2 = yield this.keychain.execute(calls, abis, transactionsDetail, true);
|
|
67
|
+
this.modal.close();
|
|
68
|
+
return res2;
|
|
70
69
|
}
|
|
71
70
|
catch (e) {
|
|
72
|
-
console.
|
|
73
|
-
|
|
74
|
-
e.message !== "not registered") {
|
|
75
|
-
console.error(e);
|
|
76
|
-
throw e;
|
|
77
|
-
}
|
|
71
|
+
console.error(e);
|
|
72
|
+
throw e;
|
|
78
73
|
}
|
|
79
|
-
(_a = this.modal) === null || _a === void 0 ? void 0 : _a.open(`${this.url}/execute?${query_string_1.default.stringify(Object.assign(Object.assign({}, transactionsDetail), { origin: window.origin, calls: JSON.stringify(calls) }))}`);
|
|
80
|
-
return this.keychain.execute(calls, abis, transactionsDetail, true);
|
|
81
74
|
});
|
|
82
75
|
}
|
|
83
76
|
/**
|
|
@@ -89,12 +82,17 @@ class DeviceAccount extends starknet_1.Account {
|
|
|
89
82
|
* @throws {Error} if the JSON object is not a valid JSON
|
|
90
83
|
*/
|
|
91
84
|
signMessage(typedData) {
|
|
92
|
-
var _a;
|
|
93
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
86
|
+
try {
|
|
87
|
+
this.modal.open();
|
|
88
|
+
const res = yield this.keychain.signMessage(typedData, this.address);
|
|
89
|
+
this.modal.close();
|
|
90
|
+
return res;
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
console.error(e);
|
|
94
|
+
throw e;
|
|
95
|
+
}
|
|
98
96
|
});
|
|
99
97
|
}
|
|
100
98
|
}
|
package/lib/device.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device.js","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"device.js","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,uCAakB;AAElB,mCAAyD;AACzD,qCAAkC;AAGlC,MAAM,aAAc,SAAQ,kBAAO;IAKjC,YACE,QAAqB,EACrB,OAAe,EACf,QAAsC,EACtC,KAAY;QAEZ,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,eAAM,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;IACG,iBAAiB,CACrB,KAAoB,EACpB,OAA4B;;YAE5B,OAAO,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,KAAK,kCACvC,OAAO,KACV,OAAO,EAAE,IAAI,CAAC,OAAO,IACrB,CAAC;QACL,CAAC;KAAA;IAEK,kBAAkB,CACtB,OAA+B,EAC/B,OAA4B;;YAE5B,OAAO,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,OAAO,kCAC1C,OAAO,KACV,OAAO,EAAE,IAAI,CAAC,OAAO,IACrB,CAAC;QACL,CAAC;KAAA;IAED;;;;;;;;;;;OAWG;IACG,OAAO,CACX,KAAo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|
|
2
|
-
import { AccountInterface, constants,
|
|
2
|
+
import { AccountInterface, constants, RpcProvider } from "starknet";
|
|
3
3
|
import { AsyncMethodReturns } from "@cartridge/penpal";
|
|
4
4
|
import { Session, Keychain, Policy } from "./types";
|
|
5
|
+
import BN from "bn.js";
|
|
5
6
|
export declare const providers: {
|
|
6
7
|
"0x534e5f474f45524c49": RpcProvider;
|
|
7
8
|
"0x534e5f474f45524c4932": RpcProvider;
|
|
8
9
|
"0x534e5f4d41494e": RpcProvider;
|
|
9
10
|
};
|
|
10
11
|
declare class Controller {
|
|
11
|
-
private selector;
|
|
12
12
|
private connection?;
|
|
13
13
|
keychain?: AsyncMethodReturns<Keychain>;
|
|
14
14
|
private policies;
|
|
@@ -29,11 +29,10 @@ declare class Controller {
|
|
|
29
29
|
register(username: string, credentialId: string, credential: {
|
|
30
30
|
x: string;
|
|
31
31
|
y: string;
|
|
32
|
-
}): Promise<{
|
|
32
|
+
}): Promise<import("./types").Error | {
|
|
33
33
|
address: string;
|
|
34
34
|
deviceKey: string;
|
|
35
35
|
} | null>;
|
|
36
|
-
saveDeploy(hash: string): Promise<void> | null;
|
|
37
36
|
login(address: string, credentialId: string, options: {
|
|
38
37
|
rpId?: string;
|
|
39
38
|
challengeExt?: Buffer;
|
|
@@ -45,11 +44,12 @@ declare class Controller {
|
|
|
45
44
|
disconnect(): Promise<void | null>;
|
|
46
45
|
revoke(origin: string, policy: Policy[]): Promise<void> | null;
|
|
47
46
|
approvals(origin: string): Promise<Session | undefined>;
|
|
47
|
+
private createModal;
|
|
48
48
|
}
|
|
49
|
-
export declare function split(n:
|
|
50
|
-
x:
|
|
51
|
-
y:
|
|
52
|
-
z:
|
|
49
|
+
export declare function split(n: BN): {
|
|
50
|
+
x: BN;
|
|
51
|
+
y: BN;
|
|
52
|
+
z: BN;
|
|
53
53
|
};
|
|
54
54
|
export * from "./types";
|
|
55
55
|
export * from "./errors";
|
package/lib/index.js
CHANGED
|
@@ -27,11 +27,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.injectController = exports.split = exports.providers = void 0;
|
|
30
|
-
const query_string_1 = __importDefault(require("query-string"));
|
|
31
30
|
const starknet_1 = require("starknet");
|
|
32
31
|
const penpal_1 = require("@cartridge/penpal");
|
|
33
32
|
const device_1 = __importDefault(require("./device"));
|
|
34
|
-
const
|
|
33
|
+
const types_1 = require("./types");
|
|
35
34
|
exports.providers = {
|
|
36
35
|
[starknet_1.constants.StarknetChainId.TESTNET]: new starknet_1.RpcProvider({
|
|
37
36
|
nodeUrl: "https://starknet-goerli.cartridge.gg/rpc/v0.2",
|
|
@@ -45,7 +44,6 @@ exports.providers = {
|
|
|
45
44
|
};
|
|
46
45
|
class Controller {
|
|
47
46
|
constructor(policies, options) {
|
|
48
|
-
this.selector = "cartridge-messenger";
|
|
49
47
|
this.policies = [];
|
|
50
48
|
this.url = "https://x.cartridge.gg";
|
|
51
49
|
this.chainId = starknet_1.constants.StarknetChainId.TESTNET;
|
|
@@ -58,34 +56,22 @@ class Controller {
|
|
|
58
56
|
if (typeof document === "undefined") {
|
|
59
57
|
return;
|
|
60
58
|
}
|
|
61
|
-
|
|
62
|
-
iframe.id = this.selector;
|
|
63
|
-
iframe.src = this.url;
|
|
64
|
-
iframe.style.opacity = "0";
|
|
65
|
-
iframe.style.height = "0";
|
|
66
|
-
iframe.style.width = "0";
|
|
67
|
-
iframe.sandbox.add("allow-scripts");
|
|
68
|
-
iframe.sandbox.add("allow-same-origin");
|
|
69
|
-
iframe.allow = "publickey-credentials-get *";
|
|
70
|
-
if (!!document.hasStorageAccess) {
|
|
71
|
-
iframe.sandbox.add("allow-storage-access-by-user-activation");
|
|
72
|
-
}
|
|
59
|
+
this.modal = this.createModal();
|
|
73
60
|
if (document.readyState === "complete" ||
|
|
74
61
|
document.readyState === "interactive") {
|
|
75
|
-
document.body.appendChild(
|
|
62
|
+
document.body.appendChild(this.modal.element);
|
|
76
63
|
}
|
|
77
64
|
else {
|
|
78
65
|
document.addEventListener("DOMContentLoaded", () => {
|
|
79
|
-
document.body.appendChild(
|
|
66
|
+
document.body.appendChild(this.modal.element);
|
|
80
67
|
});
|
|
81
68
|
}
|
|
82
69
|
this.connection = (0, penpal_1.connectToChild)({
|
|
83
|
-
iframe,
|
|
70
|
+
iframe: this.modal.element.children[0],
|
|
84
71
|
});
|
|
85
72
|
this.connection.promise
|
|
86
73
|
.then((keychain) => (this.keychain = keychain))
|
|
87
74
|
.then(() => this.probe());
|
|
88
|
-
this.modal = (0, modal_1.createModal)();
|
|
89
75
|
}
|
|
90
76
|
get account() {
|
|
91
77
|
if (!this.accounts) {
|
|
@@ -101,22 +87,20 @@ class Controller {
|
|
|
101
87
|
}
|
|
102
88
|
probe() {
|
|
103
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
if (!this.keychain) {
|
|
90
|
+
if (!this.keychain || !this.modal) {
|
|
105
91
|
console.error("not ready for connect");
|
|
106
92
|
return null;
|
|
107
93
|
}
|
|
108
94
|
try {
|
|
109
|
-
const
|
|
95
|
+
const res = yield this.keychain.probe();
|
|
96
|
+
if (res.code !== types_1.ResponseCodes.SUCCESS) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const { address } = res;
|
|
110
100
|
this.accounts = {
|
|
111
|
-
[starknet_1.constants.StarknetChainId.MAINNET]: new device_1.default(exports.providers[starknet_1.constants.StarknetChainId.MAINNET], address, this.keychain, this.modal,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
[starknet_1.constants.StarknetChainId.TESTNET]: new device_1.default(exports.providers[starknet_1.constants.StarknetChainId.TESTNET], address, this.keychain, this.modal, {
|
|
115
|
-
url: this.url,
|
|
116
|
-
}),
|
|
117
|
-
[starknet_1.constants.StarknetChainId.TESTNET2]: new device_1.default(exports.providers[starknet_1.constants.StarknetChainId.TESTNET2], address, this.keychain, this.modal, {
|
|
118
|
-
url: this.url,
|
|
119
|
-
}),
|
|
101
|
+
[starknet_1.constants.StarknetChainId.MAINNET]: new device_1.default(exports.providers[starknet_1.constants.StarknetChainId.MAINNET], address, this.keychain, this.modal),
|
|
102
|
+
[starknet_1.constants.StarknetChainId.TESTNET]: new device_1.default(exports.providers[starknet_1.constants.StarknetChainId.TESTNET], address, this.keychain, this.modal),
|
|
103
|
+
[starknet_1.constants.StarknetChainId.TESTNET2]: new device_1.default(exports.providers[starknet_1.constants.StarknetChainId.TESTNET2], address, this.keychain, this.modal),
|
|
120
104
|
};
|
|
121
105
|
}
|
|
122
106
|
catch (e) {
|
|
@@ -144,13 +128,6 @@ class Controller {
|
|
|
144
128
|
return yield this.keychain.register(username, credentialId, credential);
|
|
145
129
|
});
|
|
146
130
|
}
|
|
147
|
-
saveDeploy(hash) {
|
|
148
|
-
if (!this.keychain) {
|
|
149
|
-
console.error("not ready for connect");
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
return this.keychain.saveDeploy(hash);
|
|
153
|
-
}
|
|
154
131
|
login(address, credentialId, options) {
|
|
155
132
|
return __awaiter(this, void 0, void 0, function* () {
|
|
156
133
|
if (!this.keychain) {
|
|
@@ -170,12 +147,11 @@ class Controller {
|
|
|
170
147
|
});
|
|
171
148
|
}
|
|
172
149
|
connect() {
|
|
173
|
-
var _a;
|
|
174
150
|
return __awaiter(this, void 0, void 0, function* () {
|
|
175
151
|
if (this.accounts) {
|
|
176
152
|
return this.accounts[this.chainId];
|
|
177
153
|
}
|
|
178
|
-
if (!this.keychain) {
|
|
154
|
+
if (!this.keychain || !this.modal) {
|
|
179
155
|
console.error("not ready for connect");
|
|
180
156
|
return;
|
|
181
157
|
}
|
|
@@ -185,23 +161,26 @@ class Controller {
|
|
|
185
161
|
yield document.requestStorageAccess();
|
|
186
162
|
}
|
|
187
163
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
164
|
+
this.modal.open();
|
|
165
|
+
try {
|
|
166
|
+
let response = yield this.keychain.connect(this.policies);
|
|
167
|
+
if (response.code !== types_1.ResponseCodes.SUCCESS) {
|
|
168
|
+
throw new Error(response.message);
|
|
169
|
+
}
|
|
170
|
+
response = response;
|
|
171
|
+
this.accounts = {
|
|
172
|
+
[starknet_1.constants.StarknetChainId.MAINNET]: new device_1.default(exports.providers[starknet_1.constants.StarknetChainId.MAINNET], response.address, this.keychain, this.modal),
|
|
173
|
+
[starknet_1.constants.StarknetChainId.TESTNET]: new device_1.default(exports.providers[starknet_1.constants.StarknetChainId.TESTNET], response.address, this.keychain, this.modal),
|
|
174
|
+
[starknet_1.constants.StarknetChainId.TESTNET2]: new device_1.default(exports.providers[starknet_1.constants.StarknetChainId.TESTNET2], response.address, this.keychain, this.modal),
|
|
175
|
+
};
|
|
176
|
+
return this.accounts[this.chainId];
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
console.log(e);
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
this.modal.close();
|
|
183
|
+
}
|
|
205
184
|
});
|
|
206
185
|
}
|
|
207
186
|
disconnect() {
|
|
@@ -235,6 +214,50 @@ class Controller {
|
|
|
235
214
|
return this.keychain.approvals(origin);
|
|
236
215
|
});
|
|
237
216
|
}
|
|
217
|
+
createModal() {
|
|
218
|
+
const iframe = document.createElement("iframe");
|
|
219
|
+
iframe.src = this.url;
|
|
220
|
+
iframe.id = "cartridge-modal";
|
|
221
|
+
iframe.style.minHeight = "600px";
|
|
222
|
+
iframe.style.minWidth = "400px";
|
|
223
|
+
iframe.style.border = "none";
|
|
224
|
+
iframe.style.borderRadius = "8px";
|
|
225
|
+
iframe.sandbox.add("allow-forms");
|
|
226
|
+
iframe.sandbox.add("allow-popups");
|
|
227
|
+
iframe.sandbox.add("allow-scripts");
|
|
228
|
+
iframe.sandbox.add("allow-same-origin");
|
|
229
|
+
iframe.allow = "publickey-credentials-get *";
|
|
230
|
+
if (!!document.hasStorageAccess) {
|
|
231
|
+
iframe.sandbox.add("allow-storage-access-by-user-activation");
|
|
232
|
+
}
|
|
233
|
+
const container = document.createElement("div");
|
|
234
|
+
container.style.position = "fixed";
|
|
235
|
+
container.style.height = "100%";
|
|
236
|
+
container.style.width = "100%";
|
|
237
|
+
container.style.top = "0";
|
|
238
|
+
container.style.left = "0";
|
|
239
|
+
container.style.zIndex = "10000";
|
|
240
|
+
container.style.backgroundColor = "rgba(0,0,0,0.5)";
|
|
241
|
+
container.style.display = "flex";
|
|
242
|
+
container.style.alignItems = "center";
|
|
243
|
+
container.style.justifyContent = "center";
|
|
244
|
+
container.style.display = "none";
|
|
245
|
+
container.appendChild(iframe);
|
|
246
|
+
const open = () => {
|
|
247
|
+
container.style.display = "flex";
|
|
248
|
+
};
|
|
249
|
+
const close = () => {
|
|
250
|
+
var _a;
|
|
251
|
+
(_a = this.keychain) === null || _a === void 0 ? void 0 : _a.reset();
|
|
252
|
+
container.style.display = "none";
|
|
253
|
+
};
|
|
254
|
+
container.onclick = () => close();
|
|
255
|
+
return {
|
|
256
|
+
element: container,
|
|
257
|
+
open,
|
|
258
|
+
close,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
238
261
|
}
|
|
239
262
|
const BASE = starknet_1.number.toBN(2).pow(starknet_1.number.toBN(86));
|
|
240
263
|
function split(n) {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,uCAA4E;AAC5E,8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AAG,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC;QAElC,OAAO;YACL,OAAO,EAAE,SAAS;YAClB,IAAI;YACJ,KAAK;SACN,CAAC;IACJ,CAAC;CACF;AAED,MAAM,IAAI,GAAG,iBAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,iBAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAEjD,SAAgB,KAAK,CAAC,CAAK;IAKzB,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtB,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AACrB,CAAC;AATD,sBASC;AAED,0CAAwB;AACxB,2CAAyB;AACzB,mCAA4C;AAAnC,0GAAA,gBAAgB,OAAA;AACzB,kBAAe,UAAU,CAAC"}
|
package/lib/messenger.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const cuid_1 = __importDefault(require("cuid"));
|
|
7
|
+
class Messenger {
|
|
8
|
+
constructor(target, origin = "https://x.cartridge.gg") {
|
|
9
|
+
this.pending = [];
|
|
10
|
+
this.defaultHandler = (e) => {
|
|
11
|
+
if (e.data.target === "cartridge" &&
|
|
12
|
+
e.data.type === "request") {
|
|
13
|
+
this.pending.push(e);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
this.target = target;
|
|
17
|
+
this.origin = origin;
|
|
18
|
+
if (typeof document !== "undefined" &&
|
|
19
|
+
document.body.getAttribute("cartridge") !== "true") {
|
|
20
|
+
document.body.setAttribute("cartridge", "true");
|
|
21
|
+
}
|
|
22
|
+
window.addEventListener("message", this.defaultHandler);
|
|
23
|
+
}
|
|
24
|
+
onRequest(cb) {
|
|
25
|
+
window.removeEventListener("message", this.defaultHandler);
|
|
26
|
+
const onResponse = ({ origin, source, data: { id }, }) => (response) => {
|
|
27
|
+
if (!source) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
source.postMessage({
|
|
31
|
+
id,
|
|
32
|
+
target: "cartridge",
|
|
33
|
+
type: "response",
|
|
34
|
+
payload: Object.assign({ origin: window.origin }, response),
|
|
35
|
+
}, { targetOrigin: origin });
|
|
36
|
+
};
|
|
37
|
+
for (let i = 0; i < this.pending.length; i++) {
|
|
38
|
+
const { data: { payload }, } = this.pending[i];
|
|
39
|
+
cb(payload, onResponse(this.pending[i]));
|
|
40
|
+
}
|
|
41
|
+
window.addEventListener("message", (e) => {
|
|
42
|
+
const { data: { type, target, payload }, } = e;
|
|
43
|
+
if (target === "cartridge" &&
|
|
44
|
+
type === "request") {
|
|
45
|
+
cb(payload, onResponse(e));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
send(request) {
|
|
50
|
+
const id = (0, cuid_1.default)();
|
|
51
|
+
if (!this.target) {
|
|
52
|
+
throw new Error("read only");
|
|
53
|
+
}
|
|
54
|
+
this.target.postMessage({
|
|
55
|
+
id,
|
|
56
|
+
target: "cartridge",
|
|
57
|
+
type: "request",
|
|
58
|
+
payload: Object.assign({ origin: window.origin }, request),
|
|
59
|
+
}, this.origin);
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
const handler = ({ data }) => {
|
|
62
|
+
if (data.target === "cartridge" &&
|
|
63
|
+
data.type === "response" &&
|
|
64
|
+
id === data.id) {
|
|
65
|
+
resolve(data.payload);
|
|
66
|
+
window.removeEventListener("message", handler);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
window.addEventListener("message", handler);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.default = Messenger;
|
|
74
|
+
//# sourceMappingURL=messenger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messenger.js","sourceRoot":"","sources":["../src/messenger.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AAWxB,MAAM,SAAS;IAcb,YAAY,MAAqB,EAAE,SAAiB,wBAAwB;QAXpE,YAAO,GAAqC,EAAE,CAAA;QAE9C,mBAAc,GAAG,CAAC,CAAiC,EAAE,EAAE;YAC7D,IACE,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,WAAW;gBAC7B,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,EACzB;gBACA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;aACrB;QACH,CAAC,CAAA;QAGC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IACE,OAAO,QAAQ,KAAK,WAAW;YAC/B,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,MAAM,EAClD;YACA,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;SACjD;QAED,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;IACzD,CAAC;IAED,SAAS,CACP,EAAmE;QAEnE,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;QAE1D,MAAM,UAAU,GAAG,CAAC,EAClB,MAAM,EACN,MAAM,EACN,IAAI,EAAE,EAAE,EAAE,EAAE,GACmB,EAAE,EAAE,CAAC,CAAC,QAAkB,EAAE,EAAE;YAC3D,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B,OAAO,CACX;SACF,EACD,IAAI,CAAC,MAAM,CACZ,CAAC;QAEF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,OAAO,GAAG,CAAC,EAAE,IAAI,EAA4B,EAAE,EAAE;gBACrD,IACE,IAAI,CAAC,MAAM,KAAK,WAAW;oBAC3B,IAAI,CAAC,IAAI,KAAK,UAAU;oBACxB,EAAE,KAAK,IAAI,CAAC,EAAE,EACd;oBACA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;oBACtB,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;iBAChD;YACH,CAAC,CAAC;YACF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,SAAS,CAAC"}
|
package/lib/signer.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Signature, typedData } from "starknet";
|
|
2
|
+
import { Keychain, Modal } from "./types";
|
|
3
|
+
import { AsyncMethodReturns } from "@cartridge/penpal";
|
|
4
|
+
export declare class Signer {
|
|
5
|
+
private keychain;
|
|
6
|
+
modal: Modal;
|
|
7
|
+
constructor(keychain: AsyncMethodReturns<Keychain>, modal: Modal);
|
|
8
|
+
/**
|
|
9
|
+
* Method to get the public key of the signer
|
|
10
|
+
*
|
|
11
|
+
* @returns public key of signer as hex string with 0x prefix
|
|
12
|
+
*/
|
|
13
|
+
getPubKey(): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
16
|
+
* This adds a message prefix so it cant be interchanged with transactions
|
|
17
|
+
*
|
|
18
|
+
* @param typedData - JSON object to be signed
|
|
19
|
+
* @param accountAddress - account
|
|
20
|
+
* @returns the signature of the JSON object
|
|
21
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
22
|
+
*/
|
|
23
|
+
signMessage(typedData: typedData.TypedData, account: string): Promise<Signature>;
|
|
24
|
+
}
|
package/lib/signer.js
CHANGED
|
@@ -8,19 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.Signer = void 0;
|
|
16
|
-
const query_string_1 = __importDefault(require("query-string"));
|
|
17
13
|
class Signer {
|
|
18
|
-
constructor(keychain,
|
|
19
|
-
this.url = "https://cartridge.gg";
|
|
14
|
+
constructor(keychain, modal) {
|
|
20
15
|
this.keychain = keychain;
|
|
21
|
-
|
|
22
|
-
this.url = options.url;
|
|
23
|
-
}
|
|
16
|
+
this.modal = modal;
|
|
24
17
|
}
|
|
25
18
|
/**
|
|
26
19
|
* Method to get the public key of the signer
|
|
@@ -41,11 +34,10 @@ class Signer {
|
|
|
41
34
|
*/
|
|
42
35
|
signMessage(typedData, account) {
|
|
43
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return this.keychain.signMessage(typedData, account);
|
|
37
|
+
this.modal.open();
|
|
38
|
+
const res = yield this.keychain.signMessage(typedData, account);
|
|
39
|
+
this.modal.close();
|
|
40
|
+
return res;
|
|
49
41
|
});
|
|
50
42
|
}
|
|
51
43
|
}
|
package/lib/signer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,MAAa,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;IACU,WAAW,CACtB,SAA8B,EAC9B,OAAe;;YAEf,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAClB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YAChE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACnB,OAAO,GAAgB,CAAC;QAC1B,CAAC;KAAA;CACF;AAnCD,wBAmCC"}
|
package/lib/types.d.ts
CHANGED
|
@@ -20,16 +20,34 @@ export declare type Policy = {
|
|
|
20
20
|
target: string;
|
|
21
21
|
method?: string;
|
|
22
22
|
};
|
|
23
|
+
export declare enum ResponseCodes {
|
|
24
|
+
SUCCESS = "SUCCESS",
|
|
25
|
+
NOT_CONNECTED = "NOT_CONNECTED",
|
|
26
|
+
NOT_ALLOWED = "NOT_ALLOWED",
|
|
27
|
+
CANCELED = "CANCELED"
|
|
28
|
+
}
|
|
29
|
+
export declare type Error = {
|
|
30
|
+
code: ResponseCodes;
|
|
31
|
+
message: string;
|
|
32
|
+
};
|
|
33
|
+
export declare type ConnectReply = {
|
|
34
|
+
code: ResponseCodes.SUCCESS;
|
|
35
|
+
address: string;
|
|
36
|
+
policies: Policy[];
|
|
37
|
+
};
|
|
38
|
+
export declare type ExecuteReply = InvokeFunctionResponse & {
|
|
39
|
+
code: ResponseCodes.SUCCESS;
|
|
40
|
+
};
|
|
41
|
+
export declare type ProbeReply = {
|
|
42
|
+
code: ResponseCodes.SUCCESS;
|
|
43
|
+
address: string;
|
|
44
|
+
policies: Policy[];
|
|
45
|
+
};
|
|
23
46
|
export interface Keychain {
|
|
24
|
-
probe():
|
|
25
|
-
|
|
26
|
-
policies: Policy[];
|
|
27
|
-
};
|
|
28
|
-
connect(policies: Policy[]): {
|
|
29
|
-
address: string;
|
|
30
|
-
policies: Policy[];
|
|
31
|
-
};
|
|
47
|
+
probe(): Promise<ProbeReply | Error>;
|
|
48
|
+
connect(policies: Policy[]): Promise<ConnectReply | Error>;
|
|
32
49
|
disconnect(): void;
|
|
50
|
+
reset(): void;
|
|
33
51
|
revoke(origin: string): void;
|
|
34
52
|
approvals(origin: string): Promise<Session | undefined>;
|
|
35
53
|
estimateDeclareFee(payload: DeclareContractPayload, details?: EstimateFeeDetails & {
|
|
@@ -40,7 +58,7 @@ export interface Keychain {
|
|
|
40
58
|
}): Promise<EstimateFee>;
|
|
41
59
|
execute(calls: Call | Call[], abis?: Abi[], transactionsDetail?: InvocationsDetails & {
|
|
42
60
|
chainId?: constants.StarknetChainId;
|
|
43
|
-
}, sync?: boolean): Promise<
|
|
61
|
+
}, sync?: boolean): Promise<ExecuteReply | Error>;
|
|
44
62
|
provision(address: string, credentialId: string): Promise<string>;
|
|
45
63
|
register(username: string, credentialId: string, credential: {
|
|
46
64
|
x: string;
|
|
@@ -48,8 +66,7 @@ export interface Keychain {
|
|
|
48
66
|
}): Promise<{
|
|
49
67
|
address: string;
|
|
50
68
|
deviceKey: string;
|
|
51
|
-
}>;
|
|
52
|
-
saveDeploy(hash: string): void;
|
|
69
|
+
} | Error>;
|
|
53
70
|
login(address: string, credentialId: string, options: {
|
|
54
71
|
rpId?: string;
|
|
55
72
|
challengeExt?: Buffer;
|
|
@@ -61,9 +78,10 @@ export interface Keychain {
|
|
|
61
78
|
sessions(): Promise<{
|
|
62
79
|
[key: string]: Session;
|
|
63
80
|
}>;
|
|
64
|
-
signMessage(typedData: typedData.TypedData, account: string): Promise<Signature>;
|
|
81
|
+
signMessage(typedData: typedData.TypedData, account: string): Promise<Signature | Error>;
|
|
65
82
|
}
|
|
66
|
-
export interface
|
|
67
|
-
|
|
68
|
-
|
|
83
|
+
export interface Modal {
|
|
84
|
+
element: HTMLDivElement;
|
|
85
|
+
open: () => void;
|
|
86
|
+
close: () => void;
|
|
69
87
|
}
|
package/lib/types.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseCodes = void 0;
|
|
4
|
+
var ResponseCodes;
|
|
5
|
+
(function (ResponseCodes) {
|
|
6
|
+
ResponseCodes["SUCCESS"] = "SUCCESS";
|
|
7
|
+
ResponseCodes["NOT_CONNECTED"] = "NOT_CONNECTED";
|
|
8
|
+
ResponseCodes["NOT_ALLOWED"] = "NOT_ALLOWED";
|
|
9
|
+
ResponseCodes["CANCELED"] = "CANCELED";
|
|
10
|
+
})(ResponseCodes = exports.ResponseCodes || (exports.ResponseCodes = {}));
|
|
3
11
|
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAqCA,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,oCAAmB,CAAA;IACnB,gDAA+B,CAAA;IAC/B,4CAA2B,CAAA;IAC3B,sCAAqB,CAAA;AACvB,CAAC,EALW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAKxB"}
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Abi, Call, InvocationsSignerDetails, Signature, SignerInterface, typedData, Account, DeclareSignerDetails } from "starknet";
|
|
2
|
+
export declare type Assertion = PublicKeyCredential & {
|
|
3
|
+
response: AuthenticatorAssertionResponse;
|
|
4
|
+
};
|
|
5
|
+
export declare class WebauthnSigner implements SignerInterface {
|
|
6
|
+
private credentialId;
|
|
7
|
+
private publicKey;
|
|
8
|
+
private rpId;
|
|
9
|
+
constructor(credentialId: string, publicKey: string, rpId?: string);
|
|
10
|
+
getPubKey(): Promise<string>;
|
|
11
|
+
sign(challenge: BufferSource): Promise<Assertion>;
|
|
12
|
+
hashTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): string;
|
|
13
|
+
signTransaction(calls: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
14
|
+
signMessage(td: typedData.TypedData, accountAddress: string): Promise<Signature>;
|
|
15
|
+
signDeclareTransaction({ classHash, senderAddress, chainId, maxFee, version, nonce }: DeclareSignerDetails): Promise<Signature>;
|
|
16
|
+
}
|
|
17
|
+
declare class WebauthnAccount extends Account {
|
|
18
|
+
signer: WebauthnSigner;
|
|
19
|
+
constructor(address: string, credentialId: string, publicKey: string, options: {
|
|
20
|
+
rpId?: string;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export declare function formatAssertion(assertion: Assertion): Signature;
|
|
24
|
+
export default WebauthnAccount;
|
package/lib/webauthn.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.formatAssertion = exports.WebauthnSigner = void 0;
|
|
16
|
+
const starknet_1 = require("starknet");
|
|
17
|
+
const base64url_1 = __importDefault(require("base64url"));
|
|
18
|
+
const _1 = require(".");
|
|
19
|
+
const hash_1 = require("starknet/dist/utils/hash");
|
|
20
|
+
function convertUint8ArrayToWordArray(u8Array) {
|
|
21
|
+
var words = [], i = 0, len = u8Array.length;
|
|
22
|
+
while (i < len) {
|
|
23
|
+
words.push(((u8Array[i++] << 24) |
|
|
24
|
+
(u8Array[i++] << 16) |
|
|
25
|
+
(u8Array[i++] << 8) |
|
|
26
|
+
u8Array[i++]) >>>
|
|
27
|
+
0);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
sigBytes: words.length * 4,
|
|
31
|
+
words: words,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
class WebauthnSigner {
|
|
35
|
+
constructor(credentialId, publicKey, rpId = "cartridge.gg") {
|
|
36
|
+
this.credentialId = credentialId;
|
|
37
|
+
this.publicKey = publicKey;
|
|
38
|
+
this.rpId = rpId;
|
|
39
|
+
}
|
|
40
|
+
getPubKey() {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
return this.publicKey;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
sign(challenge) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
return (yield navigator.credentials.get({
|
|
48
|
+
publicKey: {
|
|
49
|
+
challenge,
|
|
50
|
+
timeout: 60000,
|
|
51
|
+
rpId: this.rpId,
|
|
52
|
+
allowCredentials: [
|
|
53
|
+
{
|
|
54
|
+
type: "public-key",
|
|
55
|
+
id: base64url_1.default.toBuffer(this.credentialId),
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
userVerification: "required",
|
|
59
|
+
},
|
|
60
|
+
}));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
hashTransaction(transactions, transactionsDetail, abis) {
|
|
64
|
+
if (abis && abis.length !== transactions.length) {
|
|
65
|
+
throw new Error("ABI must be provided for each transaction or no transaction");
|
|
66
|
+
}
|
|
67
|
+
// now use abi to display decoded data somewhere, but as this signer is headless, we can't do that
|
|
68
|
+
const calldata = starknet_1.transaction.fromCallsToExecuteCalldataWithNonce(transactions, transactionsDetail.nonce);
|
|
69
|
+
return starknet_1.hash.calculateTransactionHash(transactionsDetail.walletAddress, transactionsDetail.version, [starknet_1.hash.getSelectorFromName("__execute__")].concat(calldata), transactionsDetail.maxFee, transactionsDetail.chainId, transactionsDetail.nonce);
|
|
70
|
+
}
|
|
71
|
+
signTransaction(calls, transactionsDetail, abis) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
if (abis && abis.length !== calls.length) {
|
|
74
|
+
throw new Error("ABI must be provided for each transaction or no transaction");
|
|
75
|
+
}
|
|
76
|
+
// now use abi to display decoded data somewhere, but as this signer is headless, we can't do that
|
|
77
|
+
const calldata = starknet_1.transaction.fromCallsToExecuteCalldataWithNonce(calls, transactionsDetail.nonce);
|
|
78
|
+
const msgHash = starknet_1.hash.calculateTransactionHash(transactionsDetail.walletAddress, transactionsDetail.version, [starknet_1.hash.getSelectorFromName("__execute__")].concat(calldata), transactionsDetail.maxFee, transactionsDetail.chainId, transactionsDetail.nonce);
|
|
79
|
+
const challenge = Buffer.from(msgHash.slice(2).padStart(64, "0").slice(0, 64), "hex");
|
|
80
|
+
const assertion = yield this.sign(challenge);
|
|
81
|
+
return formatAssertion(assertion);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
signMessage(td, accountAddress) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const msgHash = starknet_1.typedData.getMessageHash(td, accountAddress);
|
|
87
|
+
const challenge = Buffer.from(msgHash.slice(2).padStart(64, "0").slice(0, 64), "hex");
|
|
88
|
+
const assertion = yield this.sign(challenge);
|
|
89
|
+
return formatAssertion(assertion);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
signDeclareTransaction(
|
|
93
|
+
// contractClass: ContractClass, // Should be used once class hash is present in ContractClass
|
|
94
|
+
{ classHash, senderAddress, chainId, maxFee, version, nonce }) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const msgHash = (0, hash_1.calculateDeclareTransactionHash)(classHash, senderAddress, version, maxFee, chainId, nonce);
|
|
97
|
+
const challenge = Buffer.from(msgHash.slice(2).padStart(64, "0").slice(0, 64), "hex");
|
|
98
|
+
const assertion = yield this.sign(challenge);
|
|
99
|
+
return formatAssertion(assertion);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.WebauthnSigner = WebauthnSigner;
|
|
104
|
+
class WebauthnAccount extends starknet_1.Account {
|
|
105
|
+
constructor(address, credentialId, publicKey, options) {
|
|
106
|
+
const signer = new WebauthnSigner(credentialId, publicKey, options.rpId);
|
|
107
|
+
super(starknet_1.defaultProvider, address, signer);
|
|
108
|
+
this.signer = signer;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function formatAssertion(assertion) {
|
|
112
|
+
var authenticatorDataBytes = new Uint8Array(assertion.response.authenticatorData);
|
|
113
|
+
let authenticatorDataRem = 4 - (authenticatorDataBytes.length % 4);
|
|
114
|
+
if (authenticatorDataRem == 4) {
|
|
115
|
+
authenticatorDataRem = 0;
|
|
116
|
+
}
|
|
117
|
+
const authenticatorDataWords = convertUint8ArrayToWordArray(authenticatorDataBytes).words;
|
|
118
|
+
var clientDataJSONBytes = new Uint8Array(assertion.response.clientDataJSON);
|
|
119
|
+
let clientDataJSONRem = 4 - (clientDataJSONBytes.length % 4);
|
|
120
|
+
if (clientDataJSONRem == 4) {
|
|
121
|
+
clientDataJSONRem = 0;
|
|
122
|
+
}
|
|
123
|
+
const clientDataWords = convertUint8ArrayToWordArray(clientDataJSONBytes).words;
|
|
124
|
+
// Convert signature from ASN.1 sequence to "raw" format
|
|
125
|
+
const usignature = new Uint8Array(assertion.response.signature);
|
|
126
|
+
const rStart = usignature[4] === 0 ? 5 : 4;
|
|
127
|
+
const rEnd = rStart + 32;
|
|
128
|
+
const sStart = usignature[rEnd + 2] === 0 ? rEnd + 3 : rEnd + 2;
|
|
129
|
+
const r = starknet_1.number.toBN("0x" + Buffer.from(usignature.slice(rStart, rEnd)).toString("hex"));
|
|
130
|
+
const s = starknet_1.number.toBN("0x" + Buffer.from(usignature.slice(sStart)).toString("hex"));
|
|
131
|
+
const { x: r0, y: r1, z: r2 } = (0, _1.split)(r);
|
|
132
|
+
const { x: s0, y: s1, z: s2 } = (0, _1.split)(s);
|
|
133
|
+
return [
|
|
134
|
+
"0",
|
|
135
|
+
r0.toString(),
|
|
136
|
+
r1.toString(),
|
|
137
|
+
r2.toString(),
|
|
138
|
+
s0.toString(),
|
|
139
|
+
s1.toString(),
|
|
140
|
+
s2.toString(),
|
|
141
|
+
"9",
|
|
142
|
+
"0",
|
|
143
|
+
`${clientDataWords.length}`,
|
|
144
|
+
`${clientDataJSONRem}`,
|
|
145
|
+
...clientDataWords.map((word) => `${word}`),
|
|
146
|
+
`${authenticatorDataWords.length}`,
|
|
147
|
+
`${authenticatorDataRem}`,
|
|
148
|
+
...authenticatorDataWords.map((word) => `${word}`),
|
|
149
|
+
];
|
|
150
|
+
}
|
|
151
|
+
exports.formatAssertion = formatAssertion;
|
|
152
|
+
exports.default = WebauthnAccount;
|
|
153
|
+
//# sourceMappingURL=webauthn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webauthn.js","sourceRoot":"","sources":["../src/webauthn.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAakB;AAClB,0DAAkC;AAClC,wBAA0B;AAC1B,mDAA2E;AAM3E,SAAS,4BAA4B,CAAC,OAAmB;IACvD,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,GAAG,sBAAsB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC;KACnD,CAAC;AACJ,CAAC;AAtDD,0CAsDC;AAED,kBAAe,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cartridge/controller",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Cartridge Controller",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@cartridge/penpal": "^6.2.3",
|
|
26
26
|
"base64url": "^3.0.1",
|
|
27
|
+
"bn.js": "^5.2.1",
|
|
27
28
|
"fast-deep-equal": "^3.1.3",
|
|
28
29
|
"query-string": "^7.1.1",
|
|
29
30
|
"starknet": "^4.15.1"
|
package/lib/modal.d.ts
DELETED
package/lib/modal.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createModal = void 0;
|
|
4
|
-
const penpal_1 = require("@cartridge/penpal");
|
|
5
|
-
const createModal = () => {
|
|
6
|
-
const iframe = document.createElement("iframe");
|
|
7
|
-
iframe.id = "cartridge-modal";
|
|
8
|
-
iframe.style.minHeight = "600px";
|
|
9
|
-
iframe.style.minWidth = "400px";
|
|
10
|
-
iframe.style.border = "none";
|
|
11
|
-
iframe.style.borderRadius = "8px";
|
|
12
|
-
iframe.sandbox.add("allow-forms");
|
|
13
|
-
iframe.sandbox.add("allow-popups");
|
|
14
|
-
iframe.sandbox.add("allow-scripts");
|
|
15
|
-
iframe.sandbox.add("allow-same-origin");
|
|
16
|
-
iframe.allow = "publickey-credentials-get *";
|
|
17
|
-
if (!!document.hasStorageAccess) {
|
|
18
|
-
iframe.sandbox.add("allow-storage-access-by-user-activation");
|
|
19
|
-
}
|
|
20
|
-
const container = document.createElement("div");
|
|
21
|
-
container.style.position = "fixed";
|
|
22
|
-
container.style.height = "100%";
|
|
23
|
-
container.style.width = "100%";
|
|
24
|
-
container.style.top = "0";
|
|
25
|
-
container.style.left = "0";
|
|
26
|
-
container.style.zIndex = "10000";
|
|
27
|
-
container.style.backgroundColor = "rgba(0,0,0,0.5)";
|
|
28
|
-
container.style.display = "flex";
|
|
29
|
-
container.style.alignItems = "center";
|
|
30
|
-
container.style.justifyContent = "center";
|
|
31
|
-
container.style.display = "none";
|
|
32
|
-
container.appendChild(iframe);
|
|
33
|
-
document.body.appendChild(container);
|
|
34
|
-
function open(src) {
|
|
35
|
-
iframe.src = src;
|
|
36
|
-
(0, penpal_1.connectToChild)({
|
|
37
|
-
iframe,
|
|
38
|
-
methods: {
|
|
39
|
-
onCancel: () => {
|
|
40
|
-
close();
|
|
41
|
-
},
|
|
42
|
-
onConfirm: () => {
|
|
43
|
-
close();
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
container.style.display = "flex";
|
|
48
|
-
}
|
|
49
|
-
function close() {
|
|
50
|
-
iframe.src = "about:blank";
|
|
51
|
-
container.style.display = "none";
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
open,
|
|
55
|
-
close,
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
exports.createModal = createModal;
|
|
59
|
-
//# sourceMappingURL=modal.js.map
|
package/lib/modal.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"modal.js","sourceRoot":"","sources":["../src/modal.ts"],"names":[],"mappings":";;;AAAA,8CAAmD;AAQ5C,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,CAAC,EAAE,GAAG,iBAAiB,CAAC;IAC9B,MAAM,CAAC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