@springmicro/auth 0.7.21 → 0.7.22

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.
@@ -0,0 +1,384 @@
1
+ import { e as y, h as T, a as k } from "./hashTypedData-DSWDPZpk.js";
2
+ const I = () => "9.1.0", q = (t) => t.toString(16).padStart(2, "0"), v = (t) => {
3
+ const e = new Uint8Array(t / 2);
4
+ return window.crypto.getRandomValues(e), Array.from(e, q).join("");
5
+ }, C = () => typeof window < "u" ? v(10) : (/* @__PURE__ */ new Date()).getTime().toString(36);
6
+ class g {
7
+ }
8
+ g.makeRequest = (t, e) => ({
9
+ id: C(),
10
+ method: t,
11
+ params: e,
12
+ env: {
13
+ sdkVersion: I()
14
+ }
15
+ });
16
+ g.makeResponse = (t, e, s) => ({
17
+ id: t,
18
+ success: !0,
19
+ version: s,
20
+ data: e
21
+ });
22
+ g.makeErrorResponse = (t, e, s) => ({
23
+ id: t,
24
+ success: !1,
25
+ error: e,
26
+ version: s
27
+ });
28
+ var r;
29
+ (function(t) {
30
+ t.sendTransactions = "sendTransactions", t.rpcCall = "rpcCall", t.getChainInfo = "getChainInfo", t.getSafeInfo = "getSafeInfo", t.getTxBySafeTxHash = "getTxBySafeTxHash", t.getSafeBalances = "getSafeBalances", t.signMessage = "signMessage", t.signTypedMessage = "signTypedMessage", t.getEnvironmentInfo = "getEnvironmentInfo", t.getOffChainSignature = "getOffChainSignature", t.requestAddressBook = "requestAddressBook", t.wallet_getPermissions = "wallet_getPermissions", t.wallet_requestPermissions = "wallet_requestPermissions";
31
+ })(r || (r = {}));
32
+ var m;
33
+ (function(t) {
34
+ t.requestAddressBook = "requestAddressBook";
35
+ })(m || (m = {}));
36
+ class R {
37
+ constructor(e = null, s = !1) {
38
+ this.allowedOrigins = null, this.callbacks = /* @__PURE__ */ new Map(), this.debugMode = !1, this.isServer = typeof window > "u", this.isValidMessage = ({ origin: a, data: n, source: i }) => {
39
+ const o = !n, l = !this.isServer && i === window.parent, u = typeof n.version < "u" && parseInt(n.version.split(".")[0]), B = typeof u == "number" && u >= 1;
40
+ let p = !0;
41
+ return Array.isArray(this.allowedOrigins) && (p = this.allowedOrigins.find((P) => P.test(a)) !== void 0), !o && l && B && p;
42
+ }, this.logIncomingMessage = (a) => {
43
+ console.info(`Safe Apps SDK v1: A message was received from origin ${a.origin}. `, a.data);
44
+ }, this.onParentMessage = (a) => {
45
+ this.isValidMessage(a) && (this.debugMode && this.logIncomingMessage(a), this.handleIncomingMessage(a.data));
46
+ }, this.handleIncomingMessage = (a) => {
47
+ const { id: n } = a, i = this.callbacks.get(n);
48
+ i && (i(a), this.callbacks.delete(n));
49
+ }, this.send = (a, n) => {
50
+ const i = g.makeRequest(a, n);
51
+ if (this.isServer)
52
+ throw new Error("Window doesn't exist");
53
+ return window.parent.postMessage(i, "*"), new Promise((o, l) => {
54
+ this.callbacks.set(i.id, (u) => {
55
+ if (!u.success) {
56
+ l(new Error(u.error));
57
+ return;
58
+ }
59
+ o(u);
60
+ });
61
+ });
62
+ }, this.allowedOrigins = e, this.debugMode = s, this.isServer || window.addEventListener("message", this.onParentMessage);
63
+ }
64
+ }
65
+ const b = (t) => typeof t == "object" && t != null && "domain" in t && "types" in t && "message" in t;
66
+ class H {
67
+ constructor(e) {
68
+ this.communicator = e;
69
+ }
70
+ async getBySafeTxHash(e) {
71
+ if (!e)
72
+ throw new Error("Invalid safeTxHash");
73
+ return (await this.communicator.send(r.getTxBySafeTxHash, { safeTxHash: e })).data;
74
+ }
75
+ async signMessage(e) {
76
+ const s = {
77
+ message: e
78
+ };
79
+ return (await this.communicator.send(r.signMessage, s)).data;
80
+ }
81
+ async signTypedMessage(e) {
82
+ if (!b(e))
83
+ throw new Error("Invalid typed data");
84
+ return (await this.communicator.send(r.signTypedMessage, { typedData: e })).data;
85
+ }
86
+ async send({ txs: e, params: s }) {
87
+ if (!e || !e.length)
88
+ throw new Error("No transactions were passed");
89
+ const a = {
90
+ txs: e,
91
+ params: s
92
+ };
93
+ return (await this.communicator.send(r.sendTransactions, a)).data;
94
+ }
95
+ }
96
+ const c = {
97
+ eth_call: "eth_call",
98
+ eth_gasPrice: "eth_gasPrice",
99
+ eth_getLogs: "eth_getLogs",
100
+ eth_getBalance: "eth_getBalance",
101
+ eth_getCode: "eth_getCode",
102
+ eth_getBlockByHash: "eth_getBlockByHash",
103
+ eth_getBlockByNumber: "eth_getBlockByNumber",
104
+ eth_getStorageAt: "eth_getStorageAt",
105
+ eth_getTransactionByHash: "eth_getTransactionByHash",
106
+ eth_getTransactionReceipt: "eth_getTransactionReceipt",
107
+ eth_getTransactionCount: "eth_getTransactionCount",
108
+ eth_estimateGas: "eth_estimateGas",
109
+ safe_setSettings: "safe_setSettings"
110
+ }, h = {
111
+ defaultBlockParam: (t = "latest") => t,
112
+ returnFullTxObjectParam: (t = !1) => t,
113
+ blockNumberToHex: (t) => Number.isInteger(t) ? `0x${t.toString(16)}` : t
114
+ };
115
+ class E {
116
+ constructor(e) {
117
+ this.communicator = e, this.call = this.buildRequest({
118
+ call: c.eth_call,
119
+ formatters: [null, h.defaultBlockParam]
120
+ }), this.getBalance = this.buildRequest({
121
+ call: c.eth_getBalance,
122
+ formatters: [null, h.defaultBlockParam]
123
+ }), this.getCode = this.buildRequest({
124
+ call: c.eth_getCode,
125
+ formatters: [null, h.defaultBlockParam]
126
+ }), this.getStorageAt = this.buildRequest({
127
+ call: c.eth_getStorageAt,
128
+ formatters: [null, h.blockNumberToHex, h.defaultBlockParam]
129
+ }), this.getPastLogs = this.buildRequest({
130
+ call: c.eth_getLogs
131
+ }), this.getBlockByHash = this.buildRequest({
132
+ call: c.eth_getBlockByHash,
133
+ formatters: [null, h.returnFullTxObjectParam]
134
+ }), this.getBlockByNumber = this.buildRequest({
135
+ call: c.eth_getBlockByNumber,
136
+ formatters: [h.blockNumberToHex, h.returnFullTxObjectParam]
137
+ }), this.getTransactionByHash = this.buildRequest({
138
+ call: c.eth_getTransactionByHash
139
+ }), this.getTransactionReceipt = this.buildRequest({
140
+ call: c.eth_getTransactionReceipt
141
+ }), this.getTransactionCount = this.buildRequest({
142
+ call: c.eth_getTransactionCount,
143
+ formatters: [null, h.defaultBlockParam]
144
+ }), this.getGasPrice = this.buildRequest({
145
+ call: c.eth_gasPrice
146
+ }), this.getEstimateGas = (s) => this.buildRequest({
147
+ call: c.eth_estimateGas
148
+ })([s]), this.setSafeSettings = this.buildRequest({
149
+ call: c.safe_setSettings
150
+ });
151
+ }
152
+ buildRequest(e) {
153
+ const { call: s, formatters: a } = e;
154
+ return async (n) => {
155
+ a && Array.isArray(n) && a.forEach((l, u) => {
156
+ l && (n[u] = l(n[u]));
157
+ });
158
+ const i = {
159
+ call: s,
160
+ params: n || []
161
+ };
162
+ return (await this.communicator.send(r.rpcCall, i)).data;
163
+ };
164
+ }
165
+ }
166
+ const A = "0x1626ba7e", x = "0x20c13b0b", f = 4001;
167
+ class d extends Error {
168
+ constructor(e, s, a) {
169
+ super(e), this.code = s, this.data = a, Object.setPrototypeOf(this, d.prototype);
170
+ }
171
+ }
172
+ class S {
173
+ constructor(e) {
174
+ this.communicator = e;
175
+ }
176
+ async getPermissions() {
177
+ return (await this.communicator.send(r.wallet_getPermissions, void 0)).data;
178
+ }
179
+ async requestPermissions(e) {
180
+ if (!this.isPermissionRequestValid(e))
181
+ throw new d("Permissions request is invalid", f);
182
+ try {
183
+ return (await this.communicator.send(r.wallet_requestPermissions, e)).data;
184
+ } catch {
185
+ throw new d("Permissions rejected", f);
186
+ }
187
+ }
188
+ isPermissionRequestValid(e) {
189
+ return e.every((s) => typeof s == "object" ? Object.keys(s).every((a) => !!Object.values(m).includes(a)) : !1);
190
+ }
191
+ }
192
+ const w = (t, e) => e.some((s) => s.parentCapability === t), O = () => (t, e, s) => {
193
+ const a = s.value;
194
+ return s.value = async function() {
195
+ const n = new S(this.communicator);
196
+ let i = await n.getPermissions();
197
+ if (w(e, i) || (i = await n.requestPermissions([{ [e]: {} }])), !w(e, i))
198
+ throw new d("Permissions rejected", f);
199
+ return a.apply(this);
200
+ }, s;
201
+ };
202
+ var V = function(t, e, s, a) {
203
+ var n = arguments.length, i = n < 3 ? e : a === null ? a = Object.getOwnPropertyDescriptor(e, s) : a, o;
204
+ if (typeof Reflect == "object" && typeof Reflect.decorate == "function") i = Reflect.decorate(t, e, s, a);
205
+ else for (var l = t.length - 1; l >= 0; l--) (o = t[l]) && (i = (n < 3 ? o(i) : n > 3 ? o(e, s, i) : o(e, s)) || i);
206
+ return n > 3 && i && Object.defineProperty(e, s, i), i;
207
+ };
208
+ class _ {
209
+ constructor(e) {
210
+ this.communicator = e;
211
+ }
212
+ async getChainInfo() {
213
+ return (await this.communicator.send(r.getChainInfo, void 0)).data;
214
+ }
215
+ async getInfo() {
216
+ return (await this.communicator.send(r.getSafeInfo, void 0)).data;
217
+ }
218
+ // There is a possibility that this method will change because we may add pagination to the endpoint
219
+ async experimental_getBalances({ currency: e = "usd" } = {}) {
220
+ return (await this.communicator.send(r.getSafeBalances, {
221
+ currency: e
222
+ })).data;
223
+ }
224
+ async check1271Signature(e, s = "0x") {
225
+ const a = await this.getInfo(), n = y({
226
+ abi: [
227
+ {
228
+ constant: !1,
229
+ inputs: [
230
+ {
231
+ name: "_dataHash",
232
+ type: "bytes32"
233
+ },
234
+ {
235
+ name: "_signature",
236
+ type: "bytes"
237
+ }
238
+ ],
239
+ name: "isValidSignature",
240
+ outputs: [
241
+ {
242
+ name: "",
243
+ type: "bytes4"
244
+ }
245
+ ],
246
+ payable: !1,
247
+ stateMutability: "nonpayable",
248
+ type: "function"
249
+ }
250
+ ],
251
+ functionName: "isValidSignature",
252
+ args: [e, s]
253
+ }), i = {
254
+ call: c.eth_call,
255
+ params: [
256
+ {
257
+ to: a.safeAddress,
258
+ data: n
259
+ },
260
+ "latest"
261
+ ]
262
+ };
263
+ try {
264
+ return (await this.communicator.send(r.rpcCall, i)).data.slice(0, 10).toLowerCase() === A;
265
+ } catch {
266
+ return !1;
267
+ }
268
+ }
269
+ async check1271SignatureBytes(e, s = "0x") {
270
+ const a = await this.getInfo(), n = y({
271
+ abi: [
272
+ {
273
+ constant: !1,
274
+ inputs: [
275
+ {
276
+ name: "_data",
277
+ type: "bytes"
278
+ },
279
+ {
280
+ name: "_signature",
281
+ type: "bytes"
282
+ }
283
+ ],
284
+ name: "isValidSignature",
285
+ outputs: [
286
+ {
287
+ name: "",
288
+ type: "bytes4"
289
+ }
290
+ ],
291
+ payable: !1,
292
+ stateMutability: "nonpayable",
293
+ type: "function"
294
+ }
295
+ ],
296
+ functionName: "isValidSignature",
297
+ args: [e, s]
298
+ }), i = {
299
+ call: c.eth_call,
300
+ params: [
301
+ {
302
+ to: a.safeAddress,
303
+ data: n
304
+ },
305
+ "latest"
306
+ ]
307
+ };
308
+ try {
309
+ return (await this.communicator.send(r.rpcCall, i)).data.slice(0, 10).toLowerCase() === x;
310
+ } catch {
311
+ return !1;
312
+ }
313
+ }
314
+ calculateMessageHash(e) {
315
+ return T(e);
316
+ }
317
+ calculateTypedMessageHash(e) {
318
+ const s = typeof e.domain.chainId == "object" ? e.domain.chainId.toNumber() : Number(e.domain.chainId);
319
+ let a = e.primaryType;
320
+ if (!a) {
321
+ const n = Object.values(e.types), i = Object.keys(e.types).filter((o) => n.every((l) => l.every(({ type: u }) => u.replace("[", "").replace("]", "") !== o)));
322
+ if (i.length === 0 || i.length > 1)
323
+ throw new Error("Please specify primaryType");
324
+ a = i[0];
325
+ }
326
+ return k({
327
+ message: e.message,
328
+ domain: {
329
+ ...e.domain,
330
+ chainId: s,
331
+ verifyingContract: e.domain.verifyingContract,
332
+ salt: e.domain.salt
333
+ },
334
+ types: e.types,
335
+ primaryType: a
336
+ });
337
+ }
338
+ async getOffChainSignature(e) {
339
+ return (await this.communicator.send(r.getOffChainSignature, e)).data;
340
+ }
341
+ async isMessageSigned(e, s = "0x") {
342
+ let a;
343
+ if (typeof e == "string" && (a = async () => {
344
+ const n = this.calculateMessageHash(e);
345
+ return await this.isMessageHashSigned(n, s);
346
+ }), b(e) && (a = async () => {
347
+ const n = this.calculateTypedMessageHash(e);
348
+ return await this.isMessageHashSigned(n, s);
349
+ }), a)
350
+ return await a();
351
+ throw new Error("Invalid message type");
352
+ }
353
+ async isMessageHashSigned(e, s = "0x") {
354
+ const a = [this.check1271Signature.bind(this), this.check1271SignatureBytes.bind(this)];
355
+ for (const n of a)
356
+ if (await n(e, s))
357
+ return !0;
358
+ return !1;
359
+ }
360
+ async getEnvironmentInfo() {
361
+ return (await this.communicator.send(r.getEnvironmentInfo, void 0)).data;
362
+ }
363
+ async requestAddressBook() {
364
+ return (await this.communicator.send(r.requestAddressBook, void 0)).data;
365
+ }
366
+ }
367
+ V([
368
+ O()
369
+ ], _.prototype, "requestAddressBook", null);
370
+ class j {
371
+ constructor(e = {}) {
372
+ const { allowedDomains: s = null, debug: a = !1 } = e;
373
+ this.communicator = new R(s, a), this.eth = new E(this.communicator), this.txs = new H(this.communicator), this.safe = new _(this.communicator), this.wallet = new S(this.communicator);
374
+ }
375
+ }
376
+ export {
377
+ g as MessageFormatter,
378
+ r as Methods,
379
+ c as RPC_CALLS,
380
+ m as RestrictedMethods,
381
+ j as default,
382
+ I as getSDKVersion,
383
+ b as isObjectEIP712TypedData
384
+ };
@@ -1,6 +1,6 @@
1
- import { by as r, E as e, i as o, q as s } from "./Web3Auth-DG8Yz_cD.js";
2
- import { bz as f, b3 as b, bs as d, bA as m, bB as c, bC as l, bD as p, bE as h, bF as I, bG as x, bH as E, bI as w } from "./Web3Auth-DG8Yz_cD.js";
3
- import { a as V } from "./parseEther-C7cmMVOE.js";
1
+ import { by as r, E as e, i as o, q as s } from "./Web3Auth-CYZ2tXRd.js";
2
+ import { bz as f, b3 as b, bs as d, bA as m, bB as c, bC as l, bD as p, bE as h, bF as I, bG as x, bH as E, bI as w } from "./Web3Auth-CYZ2tXRd.js";
3
+ import { a as V } from "./parseEther-B1tMovDx.js";
4
4
  const t = `
5
5
  @font-face {
6
6
  font-family: 'Inter';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { S as r, b as s, u as S } from "./index-BYJic99M.js";
1
+ import { S as r, b as s, u as S } from "./index-BQclNTiM.js";
2
2
  export {
3
3
  r as SignUp,
4
4
  s as SignUpProvider,