@cartridge/controller 0.1.46 → 0.1.48

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/index.js CHANGED
@@ -22,46 +22,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  step((generator = generator.apply(thisArg, _arguments || [])).next());
23
23
  });
24
24
  };
25
- var __generator = (this && this.__generator) || function (thisArg, body) {
26
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
- function verb(n) { return function (v) { return step([n, v]); }; }
29
- function step(op) {
30
- if (f) throw new TypeError("Generator is already executing.");
31
- while (_) try {
32
- 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;
33
- if (y = 0, t) op = [op[0] & 2, t.value];
34
- switch (op[0]) {
35
- case 0: case 1: t = op; break;
36
- case 4: _.label++; return { value: op[1], done: false };
37
- case 5: _.label++; y = op[1]; op = [0]; continue;
38
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
- default:
40
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
- if (t[2]) _.ops.pop();
45
- _.trys.pop(); continue;
46
- }
47
- op = body.call(thisArg, _);
48
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
- }
51
- };
52
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
53
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
54
27
  };
55
28
  Object.defineProperty(exports, "__esModule", { value: true });
56
29
  exports.Messenger = void 0;
57
- var cuid_1 = __importDefault(require("cuid"));
58
- var query_string_1 = __importDefault(require("query-string"));
59
- var account_js_1 = __importDefault(require("./account.js"));
60
- var messenger_js_1 = __importDefault(require("./messenger.js"));
61
- exports.Messenger = messenger_js_1.default;
62
- var Controller = /** @class */ (function () {
63
- function Controller(scopes, options) {
64
- var _this = this;
30
+ const cuid_1 = __importDefault(require("cuid"));
31
+ const query_string_1 = __importDefault(require("query-string"));
32
+ const account_1 = __importDefault(require("./account"));
33
+ const messenger_1 = __importDefault(require("./messenger"));
34
+ exports.Messenger = messenger_1.default;
35
+ class Controller {
36
+ constructor(scopes, options) {
65
37
  this.selector = "cartridge-messenger";
66
38
  this.scopes = [];
67
39
  this.url = "https://x.cartridge.gg";
@@ -73,36 +45,28 @@ var Controller = /** @class */ (function () {
73
45
  this.url = options.url;
74
46
  }
75
47
  if (typeof document !== "undefined") {
76
- this.ready_ = new Promise(function (resolve, reject) {
77
- window.addEventListener("message", function (e) { return __awaiter(_this, void 0, void 0, function () {
78
- return __generator(this, function (_a) {
79
- switch (_a.label) {
80
- case 0:
81
- if (!(e.data.target === "cartridge" &&
82
- e.data.payload.method === "ready")) return [3 /*break*/, 2];
83
- return [4 /*yield*/, this.probe()];
84
- case 1:
85
- _a.sent();
86
- this.loading = false;
87
- resolve(true);
88
- _a.label = 2;
89
- case 2: return [2 /*return*/];
90
- }
91
- });
92
- }); });
48
+ this.ready_ = new Promise((resolve, reject) => {
49
+ window.addEventListener("message", (e) => __awaiter(this, void 0, void 0, function* () {
50
+ if (e.data.target === "cartridge" &&
51
+ e.data.payload.method === "ready") {
52
+ yield this.probe();
53
+ this.loading = false;
54
+ resolve(true);
55
+ }
56
+ }));
93
57
  });
94
58
  }
95
59
  if (typeof document !== "undefined" && !this.messenger) {
96
- var iframe = document.getElementById(this.selector);
60
+ let iframe = document.getElementById(this.selector);
97
61
  if (!!iframe) {
98
62
  if (!this.messenger) {
99
- this.messenger = new messenger_js_1.default(iframe.contentWindow, this.url);
63
+ this.messenger = new messenger_1.default(iframe.contentWindow, this.url);
100
64
  }
101
65
  }
102
66
  else {
103
67
  iframe = document.createElement("iframe");
104
68
  iframe.id = this.selector;
105
- iframe.src = "".concat(this.url);
69
+ iframe.src = `${this.url}`;
106
70
  iframe.style.opacity = "0";
107
71
  iframe.style.height = "0";
108
72
  iframe.style.width = "0";
@@ -112,113 +76,83 @@ var Controller = /** @class */ (function () {
112
76
  iframe.sandbox.add("allow-storage-access-by-user-activation");
113
77
  }
114
78
  document.body.appendChild(iframe);
115
- this.messenger = new messenger_js_1.default(iframe.contentWindow, this.url);
79
+ this.messenger = new messenger_1.default(iframe.contentWindow, this.url);
116
80
  }
117
81
  }
118
82
  }
119
- Controller.prototype.ready = function () {
120
- return __awaiter(this, void 0, void 0, function () {
121
- return __generator(this, function (_a) {
122
- if (!this.loading)
123
- return [2 /*return*/, Promise.resolve(true)];
124
- return [2 /*return*/, this.ready_];
125
- });
83
+ ready() {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ if (!this.loading)
86
+ return Promise.resolve(true);
87
+ return this.ready_;
126
88
  });
127
- };
128
- Controller.prototype.probe = function () {
89
+ }
90
+ probe() {
129
91
  var _a, _b;
130
- return __awaiter(this, void 0, void 0, function () {
131
- var probe;
132
- return __generator(this, function (_c) {
133
- switch (_c.label) {
134
- case 0: return [4 /*yield*/, ((_a = this.messenger) === null || _a === void 0 ? void 0 : _a.send({
135
- method: "probe",
136
- }))];
137
- case 1:
138
- probe = _c.sent();
139
- if (this.messenger && ((_b = probe === null || probe === void 0 ? void 0 : probe.result) === null || _b === void 0 ? void 0 : _b.address)) {
140
- this.account = new account_js_1.default(probe.result.address, probe.result.scopes, this.messenger, {
141
- url: this.url,
142
- });
143
- return [2 /*return*/, this.account];
144
- }
145
- return [2 /*return*/];
146
- }
147
- });
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const probe = yield ((_a = this.messenger) === null || _a === void 0 ? void 0 : _a.send({
94
+ method: "probe",
95
+ }));
96
+ if (this.messenger && ((_b = probe === null || probe === void 0 ? void 0 : probe.result) === null || _b === void 0 ? void 0 : _b.address)) {
97
+ this.account = new account_1.default(probe.result.address, probe.result.scopes, this.messenger, {
98
+ url: this.url,
99
+ });
100
+ return this.account;
101
+ }
148
102
  });
149
- };
103
+ }
150
104
  // Register a new device key.
151
- Controller.prototype.register = function (address) {
105
+ register(address) {
152
106
  var _a;
153
- return __awaiter(this, void 0, void 0, function () {
154
- var register;
155
- return __generator(this, function (_b) {
156
- switch (_b.label) {
157
- case 0: return [4 /*yield*/, ((_a = this.messenger) === null || _a === void 0 ? void 0 : _a.send({
158
- method: "register",
159
- params: {
160
- address: address
161
- }
162
- }))];
163
- case 1:
164
- register = _b.sent();
165
- if (!register || register.error) {
166
- throw new Error("registration error");
167
- }
168
- return [2 /*return*/, register.result];
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ const register = yield ((_a = this.messenger) === null || _a === void 0 ? void 0 : _a.send({
109
+ method: "register",
110
+ params: {
111
+ address
169
112
  }
170
- });
113
+ }));
114
+ if (!register || register.error) {
115
+ throw new Error("registration error");
116
+ }
117
+ return register.result;
171
118
  });
172
- };
173
- Controller.prototype.connect = function () {
119
+ }
120
+ connect() {
174
121
  var _a;
175
- return __awaiter(this, void 0, void 0, function () {
176
- var id, ok, response;
177
- return __generator(this, function (_b) {
178
- switch (_b.label) {
179
- case 0:
180
- id = (0, cuid_1.default)();
181
- if (this.account) {
182
- return [2 /*return*/, this.account];
183
- }
184
- if (!!!document.hasStorageAccess) return [3 /*break*/, 3];
185
- return [4 /*yield*/, document.hasStorageAccess()];
186
- case 1:
187
- ok = _b.sent();
188
- if (!!ok) return [3 /*break*/, 3];
189
- return [4 /*yield*/, document.requestStorageAccess()];
190
- case 2:
191
- _b.sent();
192
- _b.label = 3;
193
- case 3:
194
- window.open("".concat(this.url, "/connect?").concat(query_string_1.default.stringify({
195
- id: id,
196
- origin: window.origin,
197
- scopes: JSON.stringify(this.scopes),
198
- })), "_blank", "height=650,width=400");
199
- return [4 /*yield*/, ((_a = this.messenger) === null || _a === void 0 ? void 0 : _a.send({
200
- method: "connect",
201
- params: {
202
- id: id,
203
- scopes: this.scopes,
204
- },
205
- }))];
206
- case 4:
207
- response = _b.sent();
208
- if (!this.messenger || !response || response.error || !response.result) {
209
- console.error("not ready for connect");
210
- return [2 /*return*/, null];
211
- }
212
- this.account = new account_js_1.default(response.result.address, response.result.scopes, this.messenger, {
213
- url: this.url,
214
- });
215
- return [2 /*return*/, this.account];
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ const id = (0, cuid_1.default)();
124
+ if (this.account) {
125
+ return this.account;
126
+ }
127
+ if (!!document.hasStorageAccess) {
128
+ const ok = yield document.hasStorageAccess();
129
+ if (!ok) {
130
+ yield document.requestStorageAccess();
216
131
  }
132
+ }
133
+ window.open(`${this.url}/connect?${query_string_1.default.stringify({
134
+ id,
135
+ origin: window.origin,
136
+ scopes: JSON.stringify(this.scopes),
137
+ })}`, "_blank", "height=650,width=400");
138
+ const response = yield ((_a = this.messenger) === null || _a === void 0 ? void 0 : _a.send({
139
+ method: "connect",
140
+ params: {
141
+ id,
142
+ scopes: this.scopes,
143
+ },
144
+ }));
145
+ if (!this.messenger || !response || response.error || !response.result) {
146
+ console.error("not ready for connect");
147
+ return null;
148
+ }
149
+ this.account = new account_1.default(response.result.address, response.result.scopes, this.messenger, {
150
+ url: this.url,
217
151
  });
152
+ return this.account;
218
153
  });
219
- };
220
- return Controller;
221
- }());
154
+ }
155
+ }
222
156
  exports.default = Controller;
223
- __exportStar(require("./types.js"), exports);
157
+ __exportStar(require("./types"), exports);
224
158
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sour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QAAQ,GAAG,MAAM,CAAA,MAAA,IAAI,CAAC,SAAS,0CAAE,IAAI,CAAkB;gBAC3D,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE;oBACN,EAAE;oBACF,MAAM,EAAE,IAAI,CAAC,MAAM;iBACpB;aACgB,CAAC,CAAA,CAAC;YAErB,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,KAAK,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;gBACtE,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAA;gBACtC,OAAO,IAAI,CAAC;aACb;YAED,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAO,CACxB,QAAQ,CAAC,MAAM,CAAC,OAAQ,EACxB,QAAQ,CAAC,MAAM,CAAC,MAAM,EACtB,IAAI,CAAC,SAAS,EACd;gBACE,GAAG,EAAE,IAAI,CAAC,GAAG;aACd,CACF,CAAC;YAEF,OAAO,IAAI,CAAC,OAAO,CAAC;;KACrB;CACF;AAED,kBAAe,UAAU,CAAC;AAG1B,0CAAwB"}
@@ -1,4 +1,4 @@
1
- import { Request, Response } from "./types.js";
1
+ import { Request, Response } from "./types";
2
2
  export declare type Message<T = Request | Response> = {
3
3
  id?: string;
4
4
  type: "request" | "response";
package/lib/messenger.js CHANGED
@@ -1,29 +1,16 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
5
  Object.defineProperty(exports, "__esModule", { value: true });
17
- var cuid_1 = __importDefault(require("cuid"));
18
- var Messenger = /** @class */ (function () {
19
- function Messenger(target, origin) {
20
- if (origin === void 0) { origin = "https://x.cartridge.gg"; }
21
- var _this = this;
6
+ const cuid_1 = __importDefault(require("cuid"));
7
+ class Messenger {
8
+ constructor(target, origin = "https://x.cartridge.gg") {
22
9
  this.pending = [];
23
- this.defaultHandler = function (e) {
10
+ this.defaultHandler = (e) => {
24
11
  if (e.data.target === "cartridge" &&
25
12
  e.data.type === "request") {
26
- _this.pending.push(e);
13
+ this.pending.push(e);
27
14
  }
28
15
  };
29
16
  this.target = target;
@@ -34,48 +21,44 @@ var Messenger = /** @class */ (function () {
34
21
  }
35
22
  window.addEventListener("message", this.defaultHandler);
36
23
  }
37
- Messenger.prototype.onRequest = function (cb) {
24
+ onRequest(cb) {
38
25
  window.removeEventListener("message", this.defaultHandler);
39
- var onResponse = function (_a) {
40
- var origin = _a.origin, source = _a.source, id = _a.data.id;
41
- return function (response) {
42
- if (!source) {
43
- return;
44
- }
45
- source.postMessage({
46
- id: id,
47
- target: "cartridge",
48
- type: "response",
49
- payload: __assign({ origin: window.origin }, response),
50
- }, { targetOrigin: origin });
51
- };
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 });
52
36
  };
53
- for (var i = 0; i < this.pending.length; i++) {
54
- var payload = this.pending[i].data.payload;
37
+ for (let i = 0; i < this.pending.length; i++) {
38
+ const { data: { payload }, } = this.pending[i];
55
39
  cb(payload, onResponse(this.pending[i]));
56
40
  }
57
- window.addEventListener("message", function (e) {
58
- var _a = e.data, type = _a.type, target = _a.target, payload = _a.payload;
41
+ window.addEventListener("message", (e) => {
42
+ const { data: { type, target, payload }, } = e;
59
43
  if (target === "cartridge" &&
60
44
  type === "request") {
61
45
  cb(payload, onResponse(e));
62
46
  }
63
47
  });
64
- };
65
- Messenger.prototype.send = function (request) {
66
- var id = (0, cuid_1.default)();
48
+ }
49
+ send(request) {
50
+ const id = (0, cuid_1.default)();
67
51
  if (!this.target) {
68
52
  throw new Error("read only");
69
53
  }
70
54
  this.target.postMessage({
71
- id: id,
55
+ id,
72
56
  target: "cartridge",
73
57
  type: "request",
74
- payload: __assign({ origin: window.origin }, request),
58
+ payload: Object.assign({ origin: window.origin }, request),
75
59
  }, this.origin);
76
- return new Promise(function (resolve, reject) {
77
- var handler = function (_a) {
78
- var data = _a.data;
60
+ return new Promise((resolve, reject) => {
61
+ const handler = ({ data }) => {
79
62
  if (data.target === "cartridge" &&
80
63
  data.type === "response" &&
81
64
  id === data.id) {
@@ -85,8 +68,7 @@ var Messenger = /** @class */ (function () {
85
68
  };
86
69
  window.addEventListener("message", handler);
87
70
  });
88
- };
89
- return Messenger;
90
- }());
71
+ }
72
+ }
91
73
  exports.default = Messenger;
92
74
  //# sourceMappingURL=messenger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"messenger.js","sourceRoot":"","sources":["../src/messenger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AAWxB;IAcE,mBAAY,MAAqB,EAAE,MAAyC;QAAzC,uBAAA,EAAA,iCAAyC;QAA5E,iBAYC;QAvBO,YAAO,GAAqC,EAAE,CAAA;QAE9C,mBAAc,GAAG,UAAC,CAAiC;YACzD,IACE,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,WAAW;gBAC7B,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,EACzB;gBACA,KAAI,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,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AAE,OAAO,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,SAAS,CAAC"}
package/lib/signer.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Abi, Invocation, InvocationsSignerDetails, SignerInterface, Signature, typedData } from "starknet";
2
- import Messenger from "./messenger.js";
2
+ import Messenger from "./messenger";
3
3
  export declare class Signer implements SignerInterface {
4
4
  private messenger;
5
5
  private url;
package/lib/signer.js CHANGED
@@ -8,42 +8,15 @@ 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 __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
- }
37
- };
38
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
13
  };
41
14
  Object.defineProperty(exports, "__esModule", { value: true });
42
15
  exports.Signer = void 0;
43
- var query_string_1 = __importDefault(require("query-string"));
44
- var cuid_1 = __importDefault(require("cuid"));
45
- var Signer = /** @class */ (function () {
46
- function Signer(messenger, options) {
16
+ const query_string_1 = __importDefault(require("query-string"));
17
+ const cuid_1 = __importDefault(require("cuid"));
18
+ class Signer {
19
+ constructor(messenger, options) {
47
20
  this.url = "https://cartridge.gg";
48
21
  this.messenger = messenger;
49
22
  if (options === null || options === void 0 ? void 0 : options.url) {
@@ -55,9 +28,9 @@ var Signer = /** @class */ (function () {
55
28
  *
56
29
  * @returns public key of signer as hex string with 0x prefix
57
30
  */
58
- Signer.prototype.getPubKey = function () {
31
+ getPubKey() {
59
32
  return Promise.resolve("");
60
- };
33
+ }
61
34
  /**
62
35
  * Sign an JSON object for off-chain usage with the starknet private key and return the signature
63
36
  * This adds a message prefix so it cant be interchanged with transactions
@@ -67,36 +40,28 @@ var Signer = /** @class */ (function () {
67
40
  * @returns the signature of the JSON object
68
41
  * @throws {Error} if the JSON object is not a valid JSON
69
42
  */
70
- Signer.prototype.signMessage = function (typedData, account) {
71
- return __awaiter(this, void 0, void 0, function () {
72
- var id, response;
73
- return __generator(this, function (_a) {
74
- switch (_a.label) {
75
- case 0:
76
- id = (0, cuid_1.default)();
77
- window.open("".concat(this.url, "/sign?").concat(query_string_1.default.stringify({
78
- id: id,
79
- origin: window.origin,
80
- message: JSON.stringify(typedData.message),
81
- })), "_blank", "height=650,width=400");
82
- return [4 /*yield*/, this.messenger.send({
83
- method: "sign-message",
84
- params: {
85
- id: id,
86
- account: account,
87
- typedData: typedData,
88
- },
89
- })];
90
- case 1:
91
- response = _a.sent();
92
- if (response.error) {
93
- throw new Error(response.error);
94
- }
95
- return [2 /*return*/, response.result];
96
- }
43
+ signMessage(typedData, account) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const id = (0, cuid_1.default)();
46
+ window.open(`${this.url}/sign?${query_string_1.default.stringify({
47
+ id,
48
+ origin: window.origin,
49
+ message: JSON.stringify(typedData.message),
50
+ })}`, "_blank", "height=650,width=400");
51
+ const response = yield this.messenger.send({
52
+ method: "sign-message",
53
+ params: {
54
+ id,
55
+ account,
56
+ typedData,
57
+ },
97
58
  });
59
+ if (response.error) {
60
+ throw new Error(response.error);
61
+ }
62
+ return response.result;
98
63
  });
99
- };
64
+ }
100
65
  /**
101
66
  * Signs a transaction with the starknet private key and returns the signature
102
67
  *
@@ -109,39 +74,30 @@ var Signer = /** @class */ (function () {
109
74
  *
110
75
  * @returns signature
111
76
  */
112
- Signer.prototype.signTransaction = function (transactions, transactionsDetail, abis) {
113
- return __awaiter(this, void 0, void 0, function () {
114
- var id, calls, response;
115
- return __generator(this, function (_a) {
116
- switch (_a.label) {
117
- case 0:
118
- id = (0, cuid_1.default)();
119
- calls = Array.isArray(transactions) ? transactions : [transactions];
120
- window.open("".concat(this.url, "/sign?").concat(query_string_1.default.stringify({
121
- id: id,
122
- origin: window.origin,
123
- calls: JSON.stringify(calls),
124
- })), "_blank", "height=650,width=400");
125
- return [4 /*yield*/, this.messenger.send({
126
- method: "sign-transaction",
127
- params: {
128
- id: id,
129
- transactions: transactions,
130
- abis: abis,
131
- transactionsDetail: transactionsDetail,
132
- },
133
- })];
134
- case 1:
135
- response = _a.sent();
136
- if (response.error) {
137
- throw new Error(response.error);
138
- }
139
- return [2 /*return*/, response.result];
140
- }
77
+ signTransaction(transactions, transactionsDetail, abis) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const id = (0, cuid_1.default)();
80
+ const calls = Array.isArray(transactions) ? transactions : [transactions];
81
+ window.open(`${this.url}/sign?${query_string_1.default.stringify({
82
+ id,
83
+ origin: window.origin,
84
+ calls: JSON.stringify(calls),
85
+ })}`, "_blank", "height=650,width=400");
86
+ const response = yield this.messenger.send({
87
+ method: "sign-transaction",
88
+ params: {
89
+ id,
90
+ transactions,
91
+ abis,
92
+ transactionsDetail,
93
+ },
141
94
  });
95
+ if (response.error) {
96
+ throw new Error(response.error);
97
+ }
98
+ return response.result;
142
99
  });
143
- };
144
- return Signer;
145
- }());
100
+ }
101
+ }
146
102
  exports.Signer = Signer;
147
103
  //# sourceMappingURL=signer.js.map