@cartridge/controller 0.1.54 → 0.1.56
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/device.d.ts +57 -0
- package/lib/device.js +130 -0
- package/lib/device.js.map +1 -0
- package/lib/index.d.ts +4 -4
- package/lib/index.js +57 -11
- package/lib/index.js.map +1 -1
- package/lib/signer.js +0 -3
- package/lib/signer.js.map +1 -1
- package/lib/types.d.ts +2 -8
- package/lib/webauthn.d.ts +19 -0
- package/lib/webauthn.js +143 -0
- package/lib/webauthn.js.map +1 -0
- package/package.json +1 -2
package/lib/device.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 { Keychain } from "./types";
|
|
3
|
+
import { AsyncMethodReturns } from "@cartridge/penpal";
|
|
4
|
+
declare class DeviceAccount extends Account {
|
|
5
|
+
address: string;
|
|
6
|
+
private keychain;
|
|
7
|
+
private url;
|
|
8
|
+
constructor(address: string, 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 DeviceAccount;
|
package/lib/device.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
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 starknet_1 = require("starknet");
|
|
16
|
+
const query_string_1 = __importDefault(require("query-string"));
|
|
17
|
+
const signer_1 = require("./signer");
|
|
18
|
+
const constants_1 = require("starknet/constants");
|
|
19
|
+
class DeviceAccount extends starknet_1.Account {
|
|
20
|
+
constructor(address, keychain, options) {
|
|
21
|
+
super(starknet_1.defaultProvider, address, new signer_1.Signer(keychain, options));
|
|
22
|
+
this.url = "https://x.cartridge.gg";
|
|
23
|
+
this.address = address;
|
|
24
|
+
this.keychain = keychain;
|
|
25
|
+
if (options === null || options === void 0 ? void 0 : options.url) {
|
|
26
|
+
this.url = options.url;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Deploys a given compiled contract (json) to starknet
|
|
31
|
+
*
|
|
32
|
+
* @param payload payload to be deployed containing:
|
|
33
|
+
* - compiled contract code
|
|
34
|
+
* - constructor calldata
|
|
35
|
+
* - address salt
|
|
36
|
+
* @param abi the abi of the contract
|
|
37
|
+
* @returns a confirmation of sending a transaction on the starknet contract
|
|
38
|
+
*/
|
|
39
|
+
deployContract(payload, abi) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
throw new Error("unimplemented");
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Estimate Fee for a method on starknet
|
|
46
|
+
*
|
|
47
|
+
* @param calls the invocation object containing:
|
|
48
|
+
* - contractAddress - the address of the contract
|
|
49
|
+
* - entrypoint - the entrypoint of the contract
|
|
50
|
+
* - calldata - (defaults to []) the calldata
|
|
51
|
+
* - signature - (defaults to []) the signature
|
|
52
|
+
*
|
|
53
|
+
* @returns response from addTransaction
|
|
54
|
+
*/
|
|
55
|
+
estimateFee(calls, details) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
return this.keychain.estimateFee(calls, details);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Invoke execute function in account contract
|
|
62
|
+
*
|
|
63
|
+
* @param calls the invocation object or an array of them, containing:
|
|
64
|
+
* - contractAddress - the address of the contract
|
|
65
|
+
* - entrypoint - the entrypoint of the contract
|
|
66
|
+
* - calldata - (defaults to []) the calldata
|
|
67
|
+
* - signature - (defaults to []) the signature
|
|
68
|
+
* @param abis (optional) the abi of the contract for better displaying
|
|
69
|
+
*
|
|
70
|
+
* @returns response from addTransaction
|
|
71
|
+
*/
|
|
72
|
+
execute(calls, abis, transactionsDetail) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
if (!transactionsDetail) {
|
|
75
|
+
transactionsDetail = {};
|
|
76
|
+
}
|
|
77
|
+
if (!transactionsDetail.nonce) {
|
|
78
|
+
transactionsDetail.nonce = 0; //await this.getNonce();
|
|
79
|
+
}
|
|
80
|
+
if (!transactionsDetail.version) {
|
|
81
|
+
transactionsDetail.version = 1;
|
|
82
|
+
}
|
|
83
|
+
if (!transactionsDetail.maxFee) {
|
|
84
|
+
try {
|
|
85
|
+
transactionsDetail.maxFee = "100"; // (await this.estimateFee(calls, { nonce: transactionsDetail.nonce })).suggestedMaxFee
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
console.error(e);
|
|
89
|
+
throw e;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
return yield this.keychain.execute(calls, abis, transactionsDetail);
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
if (e.message !== "missing scopes") {
|
|
97
|
+
console.error(e);
|
|
98
|
+
throw e;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
window.open(`${this.url}/execute?${query_string_1.default.stringify({
|
|
102
|
+
origin: window.origin,
|
|
103
|
+
calls: JSON.stringify(calls),
|
|
104
|
+
nonce: transactionsDetail.nonce,
|
|
105
|
+
version: transactionsDetail.version,
|
|
106
|
+
maxFee: transactionsDetail.maxFee,
|
|
107
|
+
chainId: constants_1.StarknetChainId.TESTNET,
|
|
108
|
+
})}`, "_blank", "height=650,width=400");
|
|
109
|
+
return this.keychain.execute(calls, abis, transactionsDetail, true);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
114
|
+
* This adds a message prefix so it cant be interchanged with transactions
|
|
115
|
+
*
|
|
116
|
+
* @param json - JSON object to be signed
|
|
117
|
+
* @returns the signature of the JSON object
|
|
118
|
+
* @throws {Error} if the JSON object is not a valid JSON
|
|
119
|
+
*/
|
|
120
|
+
signMessage(typedData) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
window.open(`${this.url}/sign?${query_string_1.default.stringify({
|
|
123
|
+
typedData: JSON.stringify(typedData),
|
|
124
|
+
})}`, "_blank", "height=650,width=400");
|
|
125
|
+
return this.keychain.signMessage(typedData, this.address);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.default = DeviceAccount;
|
|
130
|
+
//# sourceMappingURL=device.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.js","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uCAakB;AAClB,gEAA8B;AAK9B,qCAAkC;AAElC,kDAAqD;AAErD,MAAM,aAAc,SAAQ,kBAAO;IAKjC,YACE,OAAe,EACf,QAAsC,EACtC,OAEC;QAED,K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ychain?;
|
|
7
7
|
private scopes;
|
|
8
8
|
private url;
|
|
9
|
-
private loading;
|
|
10
|
-
private ready_;
|
|
11
9
|
private account;
|
|
12
10
|
constructor(scopes?: Scope[], options?: {
|
|
13
11
|
url?: string;
|
|
@@ -21,10 +19,12 @@ declare class Controller {
|
|
|
21
19
|
}): Promise<{
|
|
22
20
|
address: string;
|
|
23
21
|
deviceKey: string;
|
|
24
|
-
} | null
|
|
22
|
+
} | null>;
|
|
23
|
+
login(address: string, credentialId: string, pub: string): Promise<null | undefined>;
|
|
25
24
|
connect(): Promise<AccountInterface | null>;
|
|
26
25
|
disconnect(): Promise<void | null>;
|
|
27
26
|
}
|
|
28
|
-
export default Controller;
|
|
29
27
|
export * from "./types";
|
|
30
28
|
export * from "./errors";
|
|
29
|
+
export * from "./webauthn";
|
|
30
|
+
export default Controller;
|
package/lib/index.js
CHANGED
|
@@ -28,13 +28,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const query_string_1 = __importDefault(require("query-string"));
|
|
30
30
|
const penpal_1 = require("@cartridge/penpal");
|
|
31
|
-
const
|
|
31
|
+
const device_1 = __importDefault(require("./device"));
|
|
32
|
+
const number_1 = require("starknet/utils/number");
|
|
33
|
+
const hash_1 = require("starknet/utils/hash");
|
|
34
|
+
const shortString_1 = require("starknet/utils/shortString");
|
|
35
|
+
const webauthn_1 = __importDefault(require("./webauthn"));
|
|
36
|
+
const PROXY_CLASS = "0x793a374a266432184f68b29546d14fedfdcbe6346bc51bd34ad730e6ff914f3";
|
|
37
|
+
const ACCOUNT_CLASS = "0x21a58754bd7658d29f70e1e5dbebf84ae393a5ef704c4f5a763cc8a61cb3414";
|
|
38
|
+
const CONTROLLER_CLASS = "0x10baeb4233aae14d72f1c2f60d8c46be61436fb06631c835df93b3a9f566351";
|
|
39
|
+
const ACCOUNT_ADDRESS = "0x07d7bbf672edd77578b8864c3e2900ac9194698220adb1b1ecdc45f9222ca291";
|
|
32
40
|
class Controller {
|
|
33
41
|
constructor(scopes, options) {
|
|
34
42
|
this.selector = "cartridge-messenger";
|
|
35
43
|
this.scopes = [];
|
|
36
44
|
this.url = "https://x.cartridge.gg";
|
|
37
|
-
this.loading = true;
|
|
38
45
|
if (scopes) {
|
|
39
46
|
this.scopes = scopes;
|
|
40
47
|
}
|
|
@@ -83,8 +90,8 @@ class Controller {
|
|
|
83
90
|
return null;
|
|
84
91
|
}
|
|
85
92
|
try {
|
|
86
|
-
const { address
|
|
87
|
-
this.account = new
|
|
93
|
+
const { address } = yield this.keychain.probe();
|
|
94
|
+
this.account = new device_1.default(address, this.keychain, {
|
|
88
95
|
url: this.url,
|
|
89
96
|
});
|
|
90
97
|
}
|
|
@@ -101,12 +108,43 @@ class Controller {
|
|
|
101
108
|
console.error("not ready for connect");
|
|
102
109
|
return null;
|
|
103
110
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
111
|
+
const { x: x0, y: x1, z: x2 } = split((0, number_1.toBN)(credential.x));
|
|
112
|
+
const { x: y0, y: y1, z: y2 } = split((0, number_1.toBN)(credential.y));
|
|
113
|
+
const deviceKey = yield this.keychain.provision();
|
|
114
|
+
const address = (0, hash_1.calculateContractAddressFromHash)((0, shortString_1.encodeShortString)(username), (0, number_1.toBN)(PROXY_CLASS), [
|
|
115
|
+
(0, number_1.toBN)(ACCOUNT_CLASS),
|
|
116
|
+
(0, hash_1.getSelectorFromName)("initialize"),
|
|
117
|
+
"9",
|
|
118
|
+
(0, number_1.toBN)(CONTROLLER_CLASS),
|
|
119
|
+
"7",
|
|
120
|
+
x0,
|
|
121
|
+
x1,
|
|
122
|
+
x2,
|
|
123
|
+
y0,
|
|
124
|
+
y1,
|
|
125
|
+
y2,
|
|
126
|
+
(0, number_1.toBN)(deviceKey),
|
|
127
|
+
"12",
|
|
128
|
+
], (0, number_1.toBN)(ACCOUNT_ADDRESS));
|
|
129
|
+
return { address, deviceKey };
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
login(address, credentialId, pub) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
if (!this.keychain) {
|
|
135
|
+
console.error("not ready for connect");
|
|
136
|
+
return null;
|
|
109
137
|
}
|
|
138
|
+
const account = new webauthn_1.default(address, credentialId, pub);
|
|
139
|
+
const deviceKey = yield this.keychain.provision();
|
|
140
|
+
const calls = [
|
|
141
|
+
{
|
|
142
|
+
contractAddress: address,
|
|
143
|
+
entrypoint: "add_device_key",
|
|
144
|
+
calldata: [deviceKey],
|
|
145
|
+
},
|
|
146
|
+
];
|
|
147
|
+
yield account.execute(calls);
|
|
110
148
|
});
|
|
111
149
|
}
|
|
112
150
|
connect() {
|
|
@@ -129,7 +167,7 @@ class Controller {
|
|
|
129
167
|
scopes: JSON.stringify(this.scopes),
|
|
130
168
|
})}`, "_blank", "height=650,width=400");
|
|
131
169
|
const response = yield this.keychain.connect(this.scopes);
|
|
132
|
-
this.account = new
|
|
170
|
+
this.account = new device_1.default(response.address, this.keychain, {
|
|
133
171
|
url: this.url,
|
|
134
172
|
});
|
|
135
173
|
return this.account;
|
|
@@ -151,7 +189,15 @@ class Controller {
|
|
|
151
189
|
});
|
|
152
190
|
}
|
|
153
191
|
}
|
|
154
|
-
|
|
192
|
+
const BASE = (0, number_1.toBN)(2).pow((0, number_1.toBN)(86));
|
|
193
|
+
function split(n) {
|
|
194
|
+
const x = n.mod(BASE);
|
|
195
|
+
const y = n.div(BASE).mod(BASE);
|
|
196
|
+
const z = n.div(BASE).div(BASE);
|
|
197
|
+
return { x, y, z };
|
|
198
|
+
}
|
|
155
199
|
__exportStar(require("./types"), exports);
|
|
156
200
|
__exportStar(require("./errors"), exports);
|
|
201
|
+
__exportStar(require("./webauthn"), exports);
|
|
202
|
+
exports.default = Controller;
|
|
157
203
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAA8B;AAE9B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAA8B;AAE9B,8CAAmF;AAEnF,sDAAqC;AAErC,kDAA2D;AAC3D,8CAA4F;AAC5F,4DAA+D;AAC/D,0DAAyC;AAGzC,MAAM,WAAW,GAAG,mEAAmE,CAAC;AACxF,MAAM,aAAa,GAAG,mEAAmE,CAAC;AAC1F,MAAM,gBAAgB,GAAG,mEAAmE,CAAC;AAC7F,MAAM,eAAe,GAAG,oEAAoE,CAAC;AAE7F,MAAM,UAAU;IAQd,YACE,MAAgB,EAChB,OAGC;QAZK,aAAQ,GAAG,qBAAqB,CAAC;QAGjC,WAAM,GAAY,EAAE,CAAC;QACrB,QAAG,GAAW,wBAAwB,CAAC;QAU7C,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;SACtB;QAED,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,EAAE;YAChB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;SACxB;QAED,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;YACnC,OAAM;SACP;QAED,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC1B,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACtB,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC;QAC3B,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC;QAC1B,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG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AAC,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;AAGD,0CAAwB;AACxB,2CAAyB;AACzB,6CAA2B;AAC3B,kBAAe,UAAU,CAAC"}
|
package/lib/signer.js
CHANGED
|
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Signer = void 0;
|
|
16
16
|
const query_string_1 = __importDefault(require("query-string"));
|
|
17
|
-
const cuid_1 = __importDefault(require("cuid"));
|
|
18
17
|
class Signer {
|
|
19
18
|
constructor(keychain, options) {
|
|
20
19
|
this.url = "https://cartridge.gg";
|
|
@@ -42,9 +41,7 @@ class Signer {
|
|
|
42
41
|
*/
|
|
43
42
|
signMessage(typedData, account) {
|
|
44
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const id = (0, cuid_1.default)();
|
|
46
44
|
window.open(`${this.url}/sign?${query_string_1.default.stringify({
|
|
47
|
-
id,
|
|
48
45
|
origin: window.origin,
|
|
49
46
|
message: JSON.stringify(typedData.message),
|
|
50
47
|
})}`, "_blank", "height=650,width=400");
|
package/lib/signer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAQA,gEAA8B;
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAQA,gEAA8B;AAK9B,MAAa,MAAM;IAIf,YAAY,QAAsC,EAAE,OAEnD;QAJO,QAAG,GAAW,sBAAsB,CAAC;QAKzC,IAAI,CAAC,Q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, EstimateFee } from "starknet";
|
|
2
|
-
import { BigNumberish } from "starknet/
|
|
2
|
+
import { BigNumberish } from "starknet/utils/number";
|
|
3
3
|
export declare type Approvals = {
|
|
4
4
|
scopes: Scope[];
|
|
5
5
|
maxFee: BigNumberish;
|
|
@@ -20,13 +20,7 @@ export interface Keychain {
|
|
|
20
20
|
disconnect(): void;
|
|
21
21
|
estimateFee(calls: Call | Call[], estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFee>;
|
|
22
22
|
execute(calls: Call | Call[], abis?: Abi[], transactionsDetail?: InvocationsDetails, sync?: boolean): Promise<InvokeFunctionResponse>;
|
|
23
|
-
|
|
24
|
-
x: string;
|
|
25
|
-
y: string;
|
|
26
|
-
}): Promise<{
|
|
27
|
-
address: string;
|
|
28
|
-
deviceKey: string;
|
|
29
|
-
}>;
|
|
23
|
+
provision(): Promise<string>;
|
|
30
24
|
signMessage(typedData: typedData.TypedData, account: string): Promise<Signature>;
|
|
31
25
|
signTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
32
26
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Abi, Call, InvocationsSignerDetails, Signature, SignerInterface, typedData, Account } from "starknet";
|
|
2
|
+
declare type Assertion = PublicKeyCredential & {
|
|
3
|
+
response: AuthenticatorAssertionResponse;
|
|
4
|
+
};
|
|
5
|
+
export declare class WebauthnSigner implements SignerInterface {
|
|
6
|
+
private credentialId;
|
|
7
|
+
private publicKey;
|
|
8
|
+
constructor(credentialId: string, publicKey: string);
|
|
9
|
+
getPubKey(): Promise<string>;
|
|
10
|
+
sign(hash: string): Promise<Assertion>;
|
|
11
|
+
formatAssertion(assertion: Assertion): Signature;
|
|
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
|
+
}
|
|
16
|
+
declare class WebauthnAccount extends Account {
|
|
17
|
+
constructor(address: string, credentialId: string, publicKey: string);
|
|
18
|
+
}
|
|
19
|
+
export default WebauthnAccount;
|
package/lib/webauthn.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
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.WebauthnSigner = void 0;
|
|
16
|
+
const starknet_1 = require("starknet");
|
|
17
|
+
const base64url_1 = __importDefault(require("base64url"));
|
|
18
|
+
const BASE = starknet_1.number.toBN(2).pow(86);
|
|
19
|
+
function split(n) {
|
|
20
|
+
const x = n.mod(BASE);
|
|
21
|
+
const y = n.div(BASE).mod(BASE);
|
|
22
|
+
const z = n.div(BASE).div(BASE);
|
|
23
|
+
return { x, y, z };
|
|
24
|
+
}
|
|
25
|
+
function convertUint8ArrayToWordArray(u8Array) {
|
|
26
|
+
var words = [], i = 0, len = u8Array.length;
|
|
27
|
+
while (i < len) {
|
|
28
|
+
words.push(((u8Array[i++] << 24) |
|
|
29
|
+
(u8Array[i++] << 16) |
|
|
30
|
+
(u8Array[i++] << 8) |
|
|
31
|
+
u8Array[i++]) >>>
|
|
32
|
+
0);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
sigBytes: words.length * 4,
|
|
36
|
+
words: words,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
class WebauthnSigner {
|
|
40
|
+
constructor(credentialId, publicKey) {
|
|
41
|
+
this.credentialId = credentialId;
|
|
42
|
+
this.publicKey = publicKey;
|
|
43
|
+
}
|
|
44
|
+
getPubKey() {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
return this.publicKey;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
sign(hash) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const challenge = Buffer.from(hash.slice(2).padStart(64, "0").slice(0, 64), "hex");
|
|
52
|
+
return (yield navigator.credentials.get({
|
|
53
|
+
publicKey: {
|
|
54
|
+
challenge,
|
|
55
|
+
timeout: 60000,
|
|
56
|
+
rpId: "cartridge.gg",
|
|
57
|
+
allowCredentials: [
|
|
58
|
+
{
|
|
59
|
+
type: "public-key",
|
|
60
|
+
id: base64url_1.default.toBuffer(this.credentialId),
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
userVerification: "required",
|
|
64
|
+
},
|
|
65
|
+
}));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
formatAssertion(assertion) {
|
|
69
|
+
var authenticatorDataBytes = new Uint8Array(assertion.response.authenticatorData);
|
|
70
|
+
let authenticatorDataRem = 4 - (authenticatorDataBytes.length % 4);
|
|
71
|
+
if (authenticatorDataRem == 4) {
|
|
72
|
+
authenticatorDataRem = 0;
|
|
73
|
+
}
|
|
74
|
+
const authenticatorDataWords = convertUint8ArrayToWordArray(authenticatorDataBytes).words;
|
|
75
|
+
var clientDataJSONBytes = new Uint8Array(assertion.response.clientDataJSON);
|
|
76
|
+
let clientDataJSONRem = 4 - (clientDataJSONBytes.length % 4);
|
|
77
|
+
if (clientDataJSONRem == 4) {
|
|
78
|
+
clientDataJSONRem = 0;
|
|
79
|
+
}
|
|
80
|
+
const clientDataWords = convertUint8ArrayToWordArray(clientDataJSONBytes).words;
|
|
81
|
+
// Convert signature from ASN.1 sequence to "raw" format
|
|
82
|
+
const usignature = new Uint8Array(assertion.response.signature);
|
|
83
|
+
const rStart = usignature[4] === 0 ? 5 : 4;
|
|
84
|
+
const rEnd = rStart + 32;
|
|
85
|
+
const sStart = usignature[rEnd + 2] === 0 ? rEnd + 3 : rEnd + 2;
|
|
86
|
+
const r = starknet_1.number.toBN("0x" + Buffer.from(usignature.slice(rStart, rEnd)).toString("hex"));
|
|
87
|
+
const s = starknet_1.number.toBN("0x" + Buffer.from(usignature.slice(sStart)).toString("hex"));
|
|
88
|
+
const { x: r0, y: r1, z: r2 } = split(r);
|
|
89
|
+
const { x: s0, y: s1, z: s2 } = split(s);
|
|
90
|
+
return [
|
|
91
|
+
"0",
|
|
92
|
+
r0.toString(),
|
|
93
|
+
r1.toString(),
|
|
94
|
+
r2.toString(),
|
|
95
|
+
s0.toString(),
|
|
96
|
+
s1.toString(),
|
|
97
|
+
s2.toString(),
|
|
98
|
+
"9",
|
|
99
|
+
"0",
|
|
100
|
+
`${clientDataWords.length}`,
|
|
101
|
+
`${clientDataJSONRem}`,
|
|
102
|
+
...clientDataWords.map((word) => `${word}`),
|
|
103
|
+
`${authenticatorDataWords.length}`,
|
|
104
|
+
`${authenticatorDataRem}`,
|
|
105
|
+
...authenticatorDataWords.map((word) => `${word}`),
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
hashTransaction(transactions, transactionsDetail, abis) {
|
|
109
|
+
if (abis && abis.length !== transactions.length) {
|
|
110
|
+
throw new Error("ABI must be provided for each transaction or no transaction");
|
|
111
|
+
}
|
|
112
|
+
// now use abi to display decoded data somewhere, but as this signer is headless, we can't do that
|
|
113
|
+
const calldata = starknet_1.transaction.fromCallsToExecuteCalldataWithNonce(transactions, transactionsDetail.nonce);
|
|
114
|
+
return starknet_1.hash.calculateTransactionHash(transactionsDetail.walletAddress, transactionsDetail.version, [starknet_1.hash.getSelectorFromName("__execute__")].concat(calldata), transactionsDetail.maxFee, transactionsDetail.chainId, transactionsDetail.nonce);
|
|
115
|
+
}
|
|
116
|
+
signTransaction(calls, transactionsDetail, abis) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
if (abis && abis.length !== calls.length) {
|
|
119
|
+
throw new Error("ABI must be provided for each transaction or no transaction");
|
|
120
|
+
}
|
|
121
|
+
// now use abi to display decoded data somewhere, but as this signer is headless, we can't do that
|
|
122
|
+
const calldata = starknet_1.transaction.fromCallsToExecuteCalldataWithNonce(calls, transactionsDetail.nonce);
|
|
123
|
+
const msgHash = starknet_1.hash.calculateTransactionHash(transactionsDetail.walletAddress, transactionsDetail.version, [starknet_1.hash.getSelectorFromName("__execute__")].concat(calldata), transactionsDetail.maxFee, transactionsDetail.chainId, transactionsDetail.nonce);
|
|
124
|
+
const assertion = yield this.sign(msgHash);
|
|
125
|
+
return this.formatAssertion(assertion);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
signMessage(td, accountAddress) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
const msgHash = starknet_1.typedData.getMessageHash(td, accountAddress);
|
|
131
|
+
const assertion = yield this.sign(msgHash);
|
|
132
|
+
return this.formatAssertion(assertion);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.WebauthnSigner = WebauthnSigner;
|
|
137
|
+
class WebauthnAccount extends starknet_1.Account {
|
|
138
|
+
constructor(address, credentialId, publicKey) {
|
|
139
|
+
super(starknet_1.defaultProvider, address, new WebauthnSigner(credentialId, publicKey));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.default = WebauthnAccount;
|
|
143
|
+
//# sourceMappingURL=webauthn.js.map
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cartridge Controller",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@cartridge/penpal": "^6.2.3",
|
|
26
26
|
"base64url": "^3.0.1",
|
|
27
|
-
"cuid": "^2.1.8",
|
|
28
27
|
"fast-deep-equal": "^3.1.3",
|
|
29
28
|
"query-string": "^7.1.1",
|
|
30
29
|
"starknet": "^4.7.0"
|