@injectivelabs/wallet-privy 1.20.65 → 1.20.68
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/dist/cjs/index.cjs +46 -22
- package/dist/esm/index.js +46 -22
- package/package.json +5 -5
package/dist/cjs/index.cjs
CHANGED
|
@@ -59,14 +59,25 @@ const toPersonalSignMessage = (message) => {
|
|
|
59
59
|
if (typeof message === "string") return (0, viem.stringToHex)(message);
|
|
60
60
|
return typeof message.raw === "string" ? message.raw : (0, viem.bytesToHex)(message.raw);
|
|
61
61
|
};
|
|
62
|
+
const isOurException = (e) => e instanceof Error && (0, __injectivelabs_exceptions.isThrownException)(e);
|
|
63
|
+
const MAX_CAUSES = 5;
|
|
62
64
|
const getCauses = (e) => {
|
|
63
|
-
const causes =
|
|
64
|
-
for (let error = e; error && typeof error === "object";) {
|
|
65
|
-
|
|
66
|
-
causes.push(error);
|
|
65
|
+
const causes = /* @__PURE__ */ new Set();
|
|
66
|
+
for (let error = e; error && typeof error === "object" && causes.size < MAX_CAUSES && !causes.has(error);) {
|
|
67
|
+
causes.add(error);
|
|
67
68
|
error = error.cause;
|
|
68
69
|
}
|
|
69
|
-
return causes;
|
|
70
|
+
return [...causes];
|
|
71
|
+
};
|
|
72
|
+
const getCode = (causes) => causes.map((error) => error.code).reverse().find((code) => typeof code === "number");
|
|
73
|
+
const keepOrigin = (exception, origin) => {
|
|
74
|
+
const { stack } = origin !== null && origin !== void 0 ? origin : {};
|
|
75
|
+
if (typeof stack === "string" && stack) exception.setStack(stack);
|
|
76
|
+
return Object.defineProperty(exception, "cause", {
|
|
77
|
+
value: origin,
|
|
78
|
+
writable: true,
|
|
79
|
+
configurable: true
|
|
80
|
+
});
|
|
70
81
|
};
|
|
71
82
|
/** Signs through the Privy embedded wallet provider passed in `metadata.privy`. */
|
|
72
83
|
var PrivyWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcreteStrategy {
|
|
@@ -227,14 +238,29 @@ var PrivyWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcrete
|
|
|
227
238
|
return privy;
|
|
228
239
|
};
|
|
229
240
|
const request = async (method, params) => {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
241
|
+
try {
|
|
242
|
+
const provider = await requireSameWallet().getProvider();
|
|
243
|
+
requireSameWallet();
|
|
244
|
+
const result = await provider.request({
|
|
245
|
+
method,
|
|
246
|
+
params
|
|
247
|
+
});
|
|
248
|
+
requireSameWallet();
|
|
249
|
+
return result;
|
|
250
|
+
} catch (e) {
|
|
251
|
+
var _causes$at;
|
|
252
|
+
const causes = getCauses(e);
|
|
253
|
+
const thrown = causes.find(isOurException);
|
|
254
|
+
if (thrown) throw thrown;
|
|
255
|
+
const { message } = (_causes$at = causes.at(-1)) !== null && _causes$at !== void 0 ? _causes$at : {};
|
|
256
|
+
const code = getCode(causes);
|
|
257
|
+
throw keepOrigin(new __injectivelabs_exceptions.WalletException(new Error(typeof message === "string" ? message : String(e)), {
|
|
258
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
259
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
260
|
+
contextModule: action,
|
|
261
|
+
...typeof code === "number" ? { contextCode: code } : {}
|
|
262
|
+
}), e);
|
|
263
|
+
}
|
|
238
264
|
};
|
|
239
265
|
const sign = async ({ hash }) => normalizeSignature(await request("secp256k1_sign", [hash]));
|
|
240
266
|
return (0, viem_accounts.toAccount)({
|
|
@@ -262,20 +288,18 @@ var PrivyWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcrete
|
|
|
262
288
|
return url;
|
|
263
289
|
}
|
|
264
290
|
toWalletException(e, action) {
|
|
265
|
-
var _causes$at;
|
|
266
291
|
const causes = getCauses(e);
|
|
267
|
-
const thrown = causes.find(
|
|
292
|
+
const thrown = causes.find(isOurException);
|
|
268
293
|
if (thrown) return thrown;
|
|
269
|
-
const
|
|
270
|
-
const { message } =
|
|
271
|
-
const text = typeof shortMessage === "string" ? shortMessage : typeof message === "string" ? message : String(e);
|
|
272
|
-
|
|
273
|
-
return new __injectivelabs_exceptions.WalletException(new Error(text), {
|
|
294
|
+
const code = getCode(causes);
|
|
295
|
+
const { shortMessage, message } = e !== null && e !== void 0 ? e : {};
|
|
296
|
+
const text = typeof shortMessage === "string" && shortMessage ? shortMessage : typeof message === "string" ? message : String(e);
|
|
297
|
+
return keepOrigin(new __injectivelabs_exceptions.WalletException(new Error(text), {
|
|
274
298
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
275
299
|
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
276
300
|
contextModule: action,
|
|
277
|
-
...
|
|
278
|
-
});
|
|
301
|
+
...code !== void 0 ? { contextCode: code } : {}
|
|
302
|
+
}), e);
|
|
279
303
|
}
|
|
280
304
|
};
|
|
281
305
|
|
package/dist/esm/index.js
CHANGED
|
@@ -59,14 +59,25 @@ const toPersonalSignMessage = (message) => {
|
|
|
59
59
|
if (typeof message === "string") return stringToHex(message);
|
|
60
60
|
return typeof message.raw === "string" ? message.raw : bytesToHex(message.raw);
|
|
61
61
|
};
|
|
62
|
+
const isOurException = (e) => e instanceof Error && isThrownException(e);
|
|
63
|
+
const MAX_CAUSES = 5;
|
|
62
64
|
const getCauses = (e) => {
|
|
63
|
-
const causes =
|
|
64
|
-
for (let error = e; error && typeof error === "object";) {
|
|
65
|
-
|
|
66
|
-
causes.push(error);
|
|
65
|
+
const causes = /* @__PURE__ */ new Set();
|
|
66
|
+
for (let error = e; error && typeof error === "object" && causes.size < MAX_CAUSES && !causes.has(error);) {
|
|
67
|
+
causes.add(error);
|
|
67
68
|
error = error.cause;
|
|
68
69
|
}
|
|
69
|
-
return causes;
|
|
70
|
+
return [...causes];
|
|
71
|
+
};
|
|
72
|
+
const getCode = (causes) => causes.map((error) => error.code).reverse().find((code) => typeof code === "number");
|
|
73
|
+
const keepOrigin = (exception, origin) => {
|
|
74
|
+
const { stack } = origin !== null && origin !== void 0 ? origin : {};
|
|
75
|
+
if (typeof stack === "string" && stack) exception.setStack(stack);
|
|
76
|
+
return Object.defineProperty(exception, "cause", {
|
|
77
|
+
value: origin,
|
|
78
|
+
writable: true,
|
|
79
|
+
configurable: true
|
|
80
|
+
});
|
|
70
81
|
};
|
|
71
82
|
/** Signs through the Privy embedded wallet provider passed in `metadata.privy`. */
|
|
72
83
|
var PrivyWalletStrategy = class extends BaseConcreteStrategy {
|
|
@@ -227,14 +238,29 @@ var PrivyWalletStrategy = class extends BaseConcreteStrategy {
|
|
|
227
238
|
return privy;
|
|
228
239
|
};
|
|
229
240
|
const request = async (method, params) => {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
241
|
+
try {
|
|
242
|
+
const provider = await requireSameWallet().getProvider();
|
|
243
|
+
requireSameWallet();
|
|
244
|
+
const result = await provider.request({
|
|
245
|
+
method,
|
|
246
|
+
params
|
|
247
|
+
});
|
|
248
|
+
requireSameWallet();
|
|
249
|
+
return result;
|
|
250
|
+
} catch (e) {
|
|
251
|
+
var _causes$at;
|
|
252
|
+
const causes = getCauses(e);
|
|
253
|
+
const thrown = causes.find(isOurException);
|
|
254
|
+
if (thrown) throw thrown;
|
|
255
|
+
const { message } = (_causes$at = causes.at(-1)) !== null && _causes$at !== void 0 ? _causes$at : {};
|
|
256
|
+
const code = getCode(causes);
|
|
257
|
+
throw keepOrigin(new WalletException(new Error(typeof message === "string" ? message : String(e)), {
|
|
258
|
+
code: UnspecifiedErrorCode,
|
|
259
|
+
type: ErrorType.WalletError,
|
|
260
|
+
contextModule: action,
|
|
261
|
+
...typeof code === "number" ? { contextCode: code } : {}
|
|
262
|
+
}), e);
|
|
263
|
+
}
|
|
238
264
|
};
|
|
239
265
|
const sign = async ({ hash }) => normalizeSignature(await request("secp256k1_sign", [hash]));
|
|
240
266
|
return toAccount({
|
|
@@ -262,20 +288,18 @@ var PrivyWalletStrategy = class extends BaseConcreteStrategy {
|
|
|
262
288
|
return url;
|
|
263
289
|
}
|
|
264
290
|
toWalletException(e, action) {
|
|
265
|
-
var _causes$at;
|
|
266
291
|
const causes = getCauses(e);
|
|
267
|
-
const thrown = causes.find(
|
|
292
|
+
const thrown = causes.find(isOurException);
|
|
268
293
|
if (thrown) return thrown;
|
|
269
|
-
const
|
|
270
|
-
const { message } =
|
|
271
|
-
const text = typeof shortMessage === "string" ? shortMessage : typeof message === "string" ? message : String(e);
|
|
272
|
-
|
|
273
|
-
return new WalletException(new Error(text), {
|
|
294
|
+
const code = getCode(causes);
|
|
295
|
+
const { shortMessage, message } = e !== null && e !== void 0 ? e : {};
|
|
296
|
+
const text = typeof shortMessage === "string" && shortMessage ? shortMessage : typeof message === "string" ? message : String(e);
|
|
297
|
+
return keepOrigin(new WalletException(new Error(text), {
|
|
274
298
|
code: UnspecifiedErrorCode,
|
|
275
299
|
type: ErrorType.WalletError,
|
|
276
300
|
contextModule: action,
|
|
277
|
-
...
|
|
278
|
-
});
|
|
301
|
+
...code !== void 0 ? { contextCode: code } : {}
|
|
302
|
+
}), e);
|
|
279
303
|
}
|
|
280
304
|
};
|
|
281
305
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-privy",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.68",
|
|
4
4
|
"description": "Privy embedded wallet strategy for use with @injectivelabs/wallet-core.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"viem": "^2.54.6",
|
|
46
|
-
"@injectivelabs/
|
|
47
|
-
"@injectivelabs/
|
|
48
|
-
"@injectivelabs/wallet-base": "1.20.
|
|
49
|
-
"@injectivelabs/ts
|
|
46
|
+
"@injectivelabs/exceptions": "1.20.68",
|
|
47
|
+
"@injectivelabs/ts-types": "1.20.68",
|
|
48
|
+
"@injectivelabs/wallet-base": "1.20.68",
|
|
49
|
+
"@injectivelabs/sdk-ts": "1.20.68"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|