@cartridge/controller 0.2.19 → 0.3.1
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/constants.d.ts +31 -0
- package/lib/constants.js +38 -0
- package/lib/constants.js.map +1 -0
- package/lib/device.d.ts +3 -7
- package/lib/device.js +129 -51
- package/lib/device.js.map +1 -1
- package/lib/errors.d.ts +5 -0
- package/lib/errors.js +24 -6
- package/lib/errors.js.map +1 -1
- package/lib/generated/graphql.d.ts +3484 -0
- package/lib/generated/graphql.js +242 -0
- package/lib/generated/graphql.js.map +1 -0
- package/lib/generated/introspection.d.ts +7 -0
- package/lib/generated/introspection.js +48 -0
- package/lib/generated/introspection.js.map +1 -0
- package/lib/index.d.ts +4 -4
- package/lib/index.js +340 -168
- package/lib/index.js.map +1 -1
- package/lib/inject.d.ts +9 -2
- package/lib/inject.js +85 -41
- package/lib/inject.js.map +1 -1
- package/lib/signer.d.ts +24 -0
- package/lib/signer.js +48 -20
- 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 +15 -0
- package/lib/utils.js +54 -3
- package/lib/utils.js.map +1 -1
- package/package.json +9 -4
- package/lib/modal.d.ts +0 -8
- package/lib/modal.js +0 -59
- package/lib/modal.js.map +0 -1
package/lib/inject.js
CHANGED
|
@@ -31,12 +31,40 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (_) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
34
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
62
|
exports.injectController = exports.InjectedController = void 0;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
63
|
+
var starknet_1 = require("starknet");
|
|
64
|
+
var _1 = __importStar(require("."));
|
|
65
|
+
var InjectedController = /** @class */ (function () {
|
|
66
|
+
function InjectedController(policies, options) {
|
|
67
|
+
var _this = this;
|
|
40
68
|
this.id = "Cartridge";
|
|
41
69
|
this.name = "Cartridge";
|
|
42
70
|
this.version = "0.0.1";
|
|
@@ -44,63 +72,79 @@ class InjectedController {
|
|
|
44
72
|
this.provider = _1.providers[starknet_1.constants.StarknetChainId.MAINNET];
|
|
45
73
|
this.isConnected = false;
|
|
46
74
|
this.subscriptions = [];
|
|
47
|
-
this.request = (call)
|
|
75
|
+
this.request = function (call) {
|
|
48
76
|
throw Error("Not implemented");
|
|
49
77
|
};
|
|
50
|
-
this.enable = ()
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
this.enable = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
79
|
+
var _a;
|
|
80
|
+
return __generator(this, function (_b) {
|
|
81
|
+
switch (_b.label) {
|
|
82
|
+
case 0:
|
|
83
|
+
_a = this;
|
|
84
|
+
return [4 /*yield*/, this.controller.connect()];
|
|
85
|
+
case 1:
|
|
86
|
+
_a.account = _b.sent();
|
|
87
|
+
if (!this.account) {
|
|
88
|
+
return [2 /*return*/, []];
|
|
89
|
+
}
|
|
90
|
+
this.provider = _1.providers[this.controller.chainId];
|
|
91
|
+
this.isConnected = true;
|
|
92
|
+
return [2 /*return*/, [this.account.address]];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}); };
|
|
96
|
+
this.isPreauthorized = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
97
|
+
var _this = this;
|
|
98
|
+
return __generator(this, function (_a) {
|
|
99
|
+
return [2 /*return*/, this.controller
|
|
100
|
+
.ready()
|
|
101
|
+
.then(function () {
|
|
102
|
+
return _this.controller.probe();
|
|
103
|
+
})
|
|
104
|
+
.then(function (connected) { return !!connected; })];
|
|
105
|
+
});
|
|
106
|
+
}); };
|
|
107
|
+
this.on = function (type, handler) {
|
|
65
108
|
if (type === "accountsChanged") {
|
|
66
|
-
|
|
67
|
-
type,
|
|
68
|
-
handler,
|
|
109
|
+
_this.subscriptions.push({
|
|
110
|
+
type: type,
|
|
111
|
+
handler: handler,
|
|
69
112
|
});
|
|
70
113
|
}
|
|
71
114
|
else if (type === "networkChanged") {
|
|
72
|
-
|
|
73
|
-
type,
|
|
74
|
-
handler,
|
|
115
|
+
_this.subscriptions.push({
|
|
116
|
+
type: type,
|
|
117
|
+
handler: handler,
|
|
75
118
|
});
|
|
76
119
|
}
|
|
77
120
|
else {
|
|
78
|
-
throw new Error(
|
|
121
|
+
throw new Error("Unknwown event: ".concat(type));
|
|
79
122
|
}
|
|
80
123
|
};
|
|
81
|
-
this.off = (type, handler)
|
|
124
|
+
this.off = function (type, handler) {
|
|
82
125
|
if (type !== "accountsChanged" && type !== "networkChanged") {
|
|
83
|
-
throw new Error(
|
|
126
|
+
throw new Error("Unknwown event: ".concat(type));
|
|
84
127
|
}
|
|
85
|
-
|
|
128
|
+
var idx = _this.subscriptions.findIndex(function (userEvent) { return userEvent.type === type && userEvent.handler === handler; });
|
|
86
129
|
if (idx >= 0) {
|
|
87
|
-
|
|
130
|
+
_this.subscriptions.splice(idx, 1);
|
|
88
131
|
}
|
|
89
132
|
};
|
|
90
|
-
this.controller = new _1.default();
|
|
91
|
-
this.controller.ready().then(isConnected
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
133
|
+
this.controller = new _1.default(policies, options);
|
|
134
|
+
this.controller.ready().then(function (isConnected) {
|
|
135
|
+
_this.isConnected = !!isConnected;
|
|
136
|
+
if (_this.controller.account) {
|
|
137
|
+
_this.account = _this.controller.account;
|
|
138
|
+
_this.provider = _1.providers[_this.controller.chainId];
|
|
139
|
+
_this.selectedAddress = _this.account.address;
|
|
97
140
|
}
|
|
98
141
|
});
|
|
99
142
|
}
|
|
100
|
-
|
|
143
|
+
return InjectedController;
|
|
144
|
+
}());
|
|
101
145
|
exports.InjectedController = InjectedController;
|
|
102
|
-
function injectController() {
|
|
103
|
-
window.starknet_cartridge = new InjectedController();
|
|
146
|
+
function injectController(policies, options) {
|
|
147
|
+
window.starknet_cartridge = new InjectedController(policies, options);
|
|
104
148
|
}
|
|
105
149
|
exports.injectController = injectController;
|
|
106
150
|
//# sourceMappingURL=inject.js.map
|
package/lib/inject.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAqC;AAErC,oCAA0C;AAqE1C;IAcI,4BAAY,QAAmB,EAC3B,OAGC;QAJL,iBAcC;QA3BM,OAAE,GAAG,WAAW,CAAC;QACjB,SAAI,GAAG,WAAW,CAAC;QACnB,YAAO,GAAG,OAAO,CAAC;QAClB,SAAI,GACP,w8FAAw8F,CAAC;QACt8F,aAAQ,GAAG,YAAS,CAAC,oBAAS,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QACxD,gBAAW,GAAY,KAAK,CAAC;QAG7B,kBAAa,GAAmB,EAAE,CAAC;QAoB1C,YAAO,GAAG,UAAC,IAAgC;YACvC,MAAM,KAAK,CAAC,iBAAiB,CAAC,CAAA;QAClC,CAAC,CAAA;QAED,WAAM,GAAG;;;;;wBACL,KAAA,IAAI,CAAA;wBAAW,qBAAM,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,EAAA;;wBAA9C,GAAK,OAAO,GAAG,SAA+B,CAAA;wBAC9C,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;4BACf,sBAAO,EAAE,EAAC;yBACb;wBAED,IAAI,CAAC,QAAQ,GAAG,YAAS,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I,CAAC,EAAE;gBACV,KAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;aACrC;QACL,CAAC,CAAC;QA/DE,IAAI,CAAC,UAAU,GAAG,IAAI,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,UAAA,WAAW;YACpC,KAAI,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC;YACjC,IAAI,KAAI,CAAC,UAAU,CAAC,OAAO,EAAE;gBACzB,KAAI,CAAC,OAAO,GAAG,KAAI,CAAC,UAAU,CAAC,OAAO,CAAC;gBACvC,KAAI,CAAC,QAAQ,GAAG,YAAS,CAAC,KAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;gBACnD,KAAI,CAAC,eAAe,GAAG,KAAI,CAAC,OAAO,CAAC,OAAO,CAAC;aAC/C;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAuDL,yBAAC;AAAD,CAAC,AAnFD,IAmFC;AAnFY,gDAAkB;AAqF/B,SAAS,gBAAgB,CAAC,QAAmB,EACzC,OAGC;IACA,MAAc,CAAC,kBAAkB,GAAG,IAAI,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACnF,CAAC;AAEQ,4CAAgB"}
|
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,28 +8,48 @@ 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
|
|
12
|
-
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
13
37
|
};
|
|
14
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
39
|
exports.Signer = void 0;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
constructor(keychain, options) {
|
|
19
|
-
this.url = "https://cartridge.gg";
|
|
40
|
+
var Signer = /** @class */ (function () {
|
|
41
|
+
function Signer(keychain, modal) {
|
|
20
42
|
this.keychain = keychain;
|
|
21
|
-
|
|
22
|
-
this.url = options.url;
|
|
23
|
-
}
|
|
43
|
+
this.modal = modal;
|
|
24
44
|
}
|
|
25
45
|
/**
|
|
26
46
|
* Method to get the public key of the signer
|
|
27
47
|
*
|
|
28
48
|
* @returns public key of signer as hex string with 0x prefix
|
|
29
49
|
*/
|
|
30
|
-
getPubKey() {
|
|
50
|
+
Signer.prototype.getPubKey = function () {
|
|
31
51
|
return Promise.resolve("");
|
|
32
|
-
}
|
|
52
|
+
};
|
|
33
53
|
/**
|
|
34
54
|
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
35
55
|
* This adds a message prefix so it cant be interchanged with transactions
|
|
@@ -39,15 +59,23 @@ class Signer {
|
|
|
39
59
|
* @returns the signature of the JSON object
|
|
40
60
|
* @throws {Error} if the JSON object is not a valid JSON
|
|
41
61
|
*/
|
|
42
|
-
signMessage(typedData, account) {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
Signer.prototype.signMessage = function (typedData, account) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
+
var res;
|
|
65
|
+
return __generator(this, function (_a) {
|
|
66
|
+
switch (_a.label) {
|
|
67
|
+
case 0:
|
|
68
|
+
this.modal.open();
|
|
69
|
+
return [4 /*yield*/, this.keychain.signMessage(typedData, account)];
|
|
70
|
+
case 1:
|
|
71
|
+
res = _a.sent();
|
|
72
|
+
this.modal.close();
|
|
73
|
+
return [2 /*return*/, res];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
49
76
|
});
|
|
50
|
-
}
|
|
51
|
-
|
|
77
|
+
};
|
|
78
|
+
return Signer;
|
|
79
|
+
}());
|
|
52
80
|
exports.Signer = Signer;
|
|
53
81
|
//# sourceMappingURL=signer.js.map
|
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;IAGE,gBAAY,QAAsC,EAAE,KAAY;QAC9D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACI,0BAAS,GAAhB;QACE,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;;;OAQG;IACU,4BAAW,GAAxB,UACE,SAA8B,EAC9B,OAAe;;;;;;wBAEf,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;wBACN,qBAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,EAAA;;wBAAzD,GAAG,GAAG,SAAmD;wBAC/D,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;wBACnB,sBAAO,GAAgB,EAAC;;;;KACzB;IACH,aAAC;AAAD,CAAC,AAnCD,IAmCC;AAnCY,wBAAM"}
|
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,15 @@
|
|
|
1
|
+
import { Policy } from "./types";
|
|
2
|
+
import { GraphQLClient } from "graphql-request";
|
|
3
|
+
import BN from "bn.js";
|
|
4
|
+
export declare const ENDPOINT: string;
|
|
5
|
+
export declare const client: GraphQLClient;
|
|
6
|
+
export declare function diff(a: Policy[], b: Policy[]): Policy[];
|
|
7
|
+
export declare const computeAddress: (username: string, { x0, x1, x2 }: {
|
|
8
|
+
x0: BN;
|
|
9
|
+
x1: BN;
|
|
10
|
+
x2: BN;
|
|
11
|
+
}, { y0, y1, y2 }: {
|
|
12
|
+
y0: BN;
|
|
13
|
+
y1: BN;
|
|
14
|
+
y2: BN;
|
|
15
|
+
}, deviceKey: string) => string;
|
package/lib/utils.js
CHANGED
|
@@ -1,12 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
2
27
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
28
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
29
|
};
|
|
5
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.diff = void 0;
|
|
7
|
-
|
|
31
|
+
exports.computeAddress = exports.diff = exports.client = exports.ENDPOINT = void 0;
|
|
32
|
+
var fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
33
|
+
var graphql_request_1 = require("graphql-request");
|
|
34
|
+
var starknet_1 = require("starknet");
|
|
35
|
+
var constants_1 = require("@cartridge/controller/src/constants");
|
|
36
|
+
exports.ENDPOINT = process.env.NEXT_PUBLIC_API_URL;
|
|
37
|
+
exports.client = new graphql_request_1.GraphQLClient(exports.ENDPOINT, { credentials: "include" });
|
|
8
38
|
function diff(a, b) {
|
|
9
|
-
return a.reduce((prev, policyA)
|
|
39
|
+
return a.reduce(function (prev, policyA) {
|
|
40
|
+
return b.some(function (policyB) { return (0, fast_deep_equal_1.default)(policyB, policyA); }) ? prev : __spreadArray(__spreadArray([], __read(prev), false), [policyA], false);
|
|
41
|
+
}, []);
|
|
10
42
|
}
|
|
11
43
|
exports.diff = diff;
|
|
44
|
+
var computeAddress = function (username, _a, _b, deviceKey) {
|
|
45
|
+
var x0 = _a.x0, x1 = _a.x1, x2 = _a.x2;
|
|
46
|
+
var y0 = _b.y0, y1 = _b.y1, y2 = _b.y2;
|
|
47
|
+
return starknet_1.hash.calculateContractAddressFromHash(starknet_1.shortString.encodeShortString(username), starknet_1.number.toBN(constants_1.PROXY_CLASS), [
|
|
48
|
+
starknet_1.number.toBN(constants_1.CLASS_HASHES["0.0.1"].account),
|
|
49
|
+
starknet_1.hash.getSelectorFromName("initialize"),
|
|
50
|
+
"9",
|
|
51
|
+
starknet_1.number.toBN(constants_1.CLASS_HASHES["0.0.1"].controller),
|
|
52
|
+
"7",
|
|
53
|
+
x0,
|
|
54
|
+
x1,
|
|
55
|
+
x2,
|
|
56
|
+
y0,
|
|
57
|
+
y1,
|
|
58
|
+
y2,
|
|
59
|
+
starknet_1.number.toBN(deviceKey),
|
|
60
|
+
], "0");
|
|
61
|
+
};
|
|
62
|
+
exports.computeAddress = computeAddress;
|
|
12
63
|
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oEAAoC;AAEpC,mDAAgD;AAChD,qCAAqD;AAErD,iEAAgF;AAEnE,QAAA,QAA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.json
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cartridge/controller",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Cartridge Controller",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
8
|
+
"build": "tsc --build tsconfig.json",
|
|
9
9
|
"dev": "tsc --watch",
|
|
10
|
-
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\""
|
|
10
|
+
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
11
|
+
"gen": "graphql-codegen --config codegen.yaml"
|
|
11
12
|
},
|
|
12
13
|
"files": [
|
|
13
14
|
"lib"
|
|
14
15
|
],
|
|
15
16
|
"devDependencies": {
|
|
17
|
+
"@graphql-codegen/cli": "^2.16.4",
|
|
16
18
|
"@types/jest": "^26.0.18",
|
|
17
19
|
"@types/node": "^17.0.23",
|
|
20
|
+
"graphql": "^16.3.0",
|
|
21
|
+
"graphql-request": "^5.0.0",
|
|
18
22
|
"jest": "^26.6.3",
|
|
19
23
|
"ts-jest": "^26.5.1",
|
|
20
24
|
"ts-node": "^10.4.0",
|
|
@@ -25,8 +29,9 @@
|
|
|
25
29
|
"@cartridge/penpal": "^6.2.3",
|
|
26
30
|
"base64url": "^3.0.1",
|
|
27
31
|
"bn.js": "^5.2.1",
|
|
32
|
+
"cbor-x": "^1.5.0",
|
|
28
33
|
"fast-deep-equal": "^3.1.3",
|
|
29
34
|
"query-string": "^7.1.1",
|
|
30
|
-
"starknet": "^4.
|
|
35
|
+
"starknet": "^4.17.1"
|
|
31
36
|
}
|
|
32
37
|
}
|
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
|
-
container.style.display = "flex";
|
|
36
|
-
iframe.src = src;
|
|
37
|
-
(0, penpal_1.connectToChild)({
|
|
38
|
-
iframe,
|
|
39
|
-
methods: {
|
|
40
|
-
onCancel: () => {
|
|
41
|
-
close();
|
|
42
|
-
},
|
|
43
|
-
onConfirm: () => {
|
|
44
|
-
close();
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
function close() {
|
|
50
|
-
container.style.display = "none";
|
|
51
|
-
iframe.src = "about:blank";
|
|
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,KAAK,CAAC,SAAS,GAAG,OAAO,CAAC;IACjC,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC;IAChC,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;IAC7B,MAAM,CAAC,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC;IAClC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAClC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACnC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACpC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACxC,MAAM,CAAC,KAAK,GAAG,6BAA6B,CAAC;IAC7C,IAAI,CAAC,CAAC,QAAQ,CAAC,gBAAgB,EAAE;QAC/B,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;KAC/D;IAED,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAChD,SAAS,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC;IACn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