unwallet-client-sdk 0.17.0 → 0.18.0
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/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +17 -55
- package/dist/index.mjs +18 -41
- package/package.json +9 -14
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Address, Hex } from 'viem';
|
|
2
|
+
|
|
1
3
|
declare const VALID_ENVS: readonly ["prod", "dev"];
|
|
2
4
|
type Env = (typeof VALID_ENVS)[number];
|
|
3
5
|
interface Config {
|
|
@@ -19,8 +21,8 @@ interface EIP712TypedDataDomain {
|
|
|
19
21
|
name?: string;
|
|
20
22
|
version?: string;
|
|
21
23
|
chainId?: number;
|
|
22
|
-
verifyingContract?:
|
|
23
|
-
salt?:
|
|
24
|
+
verifyingContract?: Address;
|
|
25
|
+
salt?: Hex;
|
|
24
26
|
}
|
|
25
27
|
interface EIP712TypedDataField {
|
|
26
28
|
name: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Address, Hex } from 'viem';
|
|
2
|
+
|
|
1
3
|
declare const VALID_ENVS: readonly ["prod", "dev"];
|
|
2
4
|
type Env = (typeof VALID_ENVS)[number];
|
|
3
5
|
interface Config {
|
|
@@ -19,8 +21,8 @@ interface EIP712TypedDataDomain {
|
|
|
19
21
|
name?: string;
|
|
20
22
|
version?: string;
|
|
21
23
|
chainId?: number;
|
|
22
|
-
verifyingContract?:
|
|
23
|
-
salt?:
|
|
24
|
+
verifyingContract?: Address;
|
|
25
|
+
salt?: Hex;
|
|
24
26
|
}
|
|
25
27
|
interface EIP712TypedDataField {
|
|
26
28
|
name: string;
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
@@ -46,8 +36,7 @@ _UWError.prototype.name = "UWError";
|
|
|
46
36
|
var UWError = _UWError;
|
|
47
37
|
|
|
48
38
|
// src/unwallet.ts
|
|
49
|
-
var
|
|
50
|
-
var import_omit = __toESM(require("lodash/omit"));
|
|
39
|
+
var import_viem = require("viem");
|
|
51
40
|
|
|
52
41
|
// src/config.ts
|
|
53
42
|
var UNWALLET_CONFIG_PROD = {
|
|
@@ -78,7 +67,7 @@ function getUnWalletConfigByEnv(env) {
|
|
|
78
67
|
}
|
|
79
68
|
|
|
80
69
|
// src/x.ts
|
|
81
|
-
var
|
|
70
|
+
var import_zod = require("zod");
|
|
82
71
|
var VALID_X_RESPONSE_TYPES = [
|
|
83
72
|
"connectionID",
|
|
84
73
|
"signature",
|
|
@@ -181,7 +170,7 @@ var XConnection = class _XConnection {
|
|
|
181
170
|
}
|
|
182
171
|
};
|
|
183
172
|
function safeParseMessageEventDataToXResponse(data) {
|
|
184
|
-
const result =
|
|
173
|
+
const result = import_zod.z.string().refine(
|
|
185
174
|
(val) => {
|
|
186
175
|
try {
|
|
187
176
|
JSON.parse(val);
|
|
@@ -195,9 +184,9 @@ function safeParseMessageEventDataToXResponse(data) {
|
|
|
195
184
|
message: "Invalid JSON string"
|
|
196
185
|
}
|
|
197
186
|
).transform((val) => JSON.parse(val)).pipe(
|
|
198
|
-
|
|
199
|
-
type:
|
|
200
|
-
value:
|
|
187
|
+
import_zod.z.object({
|
|
188
|
+
type: import_zod.z.enum(VALID_X_RESPONSE_TYPES),
|
|
189
|
+
value: import_zod.z.string()
|
|
201
190
|
})
|
|
202
191
|
).safeParse(data);
|
|
203
192
|
if (!result.success) {
|
|
@@ -265,7 +254,7 @@ var UnWallet = class _UnWallet {
|
|
|
265
254
|
reject(new UWError("REQUEST_IN_PROGRESS"));
|
|
266
255
|
return;
|
|
267
256
|
}
|
|
268
|
-
const digest =
|
|
257
|
+
const digest = (0, import_viem.sha256)((0, import_viem.toBytes)(args.message));
|
|
269
258
|
this.xConnection.setResponseHandler({
|
|
270
259
|
resolve: (resp) => {
|
|
271
260
|
this.xConnection.setResponseHandler(null);
|
|
@@ -308,50 +297,23 @@ var UnWallet = class _UnWallet {
|
|
|
308
297
|
reject(new UWError("REQUEST_IN_PROGRESS"));
|
|
309
298
|
return;
|
|
310
299
|
}
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
new UWError("INVALID_REQUEST", `invalid typed data: ${e.message}`)
|
|
320
|
-
);
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
reject(e);
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
if (primaryType !== args.typedData.primaryType) {
|
|
300
|
+
const { EIP712Domain: _, ...typedDataTypes } = args.typedData.types;
|
|
301
|
+
const typedData = {
|
|
302
|
+
...args.typedData,
|
|
303
|
+
types: typedDataTypes
|
|
304
|
+
};
|
|
305
|
+
try {
|
|
306
|
+
(0, import_viem.validateTypedData)(typedData);
|
|
307
|
+
} catch (e) {
|
|
328
308
|
reject(
|
|
329
309
|
new UWError(
|
|
330
310
|
"INVALID_REQUEST",
|
|
331
|
-
`invalid typed data:
|
|
311
|
+
`invalid typed data: ${e.message}`
|
|
332
312
|
)
|
|
333
313
|
);
|
|
334
314
|
return;
|
|
335
315
|
}
|
|
336
|
-
|
|
337
|
-
{
|
|
338
|
-
try {
|
|
339
|
-
digest = import_ethers.ethers.TypedDataEncoder.hash(
|
|
340
|
-
args.typedData.domain,
|
|
341
|
-
types,
|
|
342
|
-
args.typedData.message
|
|
343
|
-
);
|
|
344
|
-
} catch (e) {
|
|
345
|
-
if (import_ethers.ethers.isError(e, "INVALID_ARGUMENT")) {
|
|
346
|
-
reject(
|
|
347
|
-
new UWError("INVALID_REQUEST", `invalid typed data: ${e.message}`)
|
|
348
|
-
);
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
reject(e);
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
316
|
+
const digest = (0, import_viem.hashTypedData)(typedData);
|
|
355
317
|
this.xConnection.setResponseHandler({
|
|
356
318
|
resolve: (resp) => {
|
|
357
319
|
this.xConnection.setResponseHandler(null);
|
package/dist/index.mjs
CHANGED
|
@@ -9,8 +9,12 @@ _UWError.prototype.name = "UWError";
|
|
|
9
9
|
var UWError = _UWError;
|
|
10
10
|
|
|
11
11
|
// src/unwallet.ts
|
|
12
|
-
import {
|
|
13
|
-
|
|
12
|
+
import {
|
|
13
|
+
hashTypedData,
|
|
14
|
+
toBytes,
|
|
15
|
+
sha256,
|
|
16
|
+
validateTypedData
|
|
17
|
+
} from "viem";
|
|
14
18
|
|
|
15
19
|
// src/config.ts
|
|
16
20
|
var UNWALLET_CONFIG_PROD = {
|
|
@@ -41,7 +45,7 @@ function getUnWalletConfigByEnv(env) {
|
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
// src/x.ts
|
|
44
|
-
import { z } from "zod
|
|
48
|
+
import { z } from "zod";
|
|
45
49
|
var VALID_X_RESPONSE_TYPES = [
|
|
46
50
|
"connectionID",
|
|
47
51
|
"signature",
|
|
@@ -228,7 +232,7 @@ var UnWallet = class _UnWallet {
|
|
|
228
232
|
reject(new UWError("REQUEST_IN_PROGRESS"));
|
|
229
233
|
return;
|
|
230
234
|
}
|
|
231
|
-
const digest =
|
|
235
|
+
const digest = sha256(toBytes(args.message));
|
|
232
236
|
this.xConnection.setResponseHandler({
|
|
233
237
|
resolve: (resp) => {
|
|
234
238
|
this.xConnection.setResponseHandler(null);
|
|
@@ -271,50 +275,23 @@ var UnWallet = class _UnWallet {
|
|
|
271
275
|
reject(new UWError("REQUEST_IN_PROGRESS"));
|
|
272
276
|
return;
|
|
273
277
|
}
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
new UWError("INVALID_REQUEST", `invalid typed data: ${e.message}`)
|
|
283
|
-
);
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
reject(e);
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
if (primaryType !== args.typedData.primaryType) {
|
|
278
|
+
const { EIP712Domain: _, ...typedDataTypes } = args.typedData.types;
|
|
279
|
+
const typedData = {
|
|
280
|
+
...args.typedData,
|
|
281
|
+
types: typedDataTypes
|
|
282
|
+
};
|
|
283
|
+
try {
|
|
284
|
+
validateTypedData(typedData);
|
|
285
|
+
} catch (e) {
|
|
291
286
|
reject(
|
|
292
287
|
new UWError(
|
|
293
288
|
"INVALID_REQUEST",
|
|
294
|
-
`invalid typed data:
|
|
289
|
+
`invalid typed data: ${e.message}`
|
|
295
290
|
)
|
|
296
291
|
);
|
|
297
292
|
return;
|
|
298
293
|
}
|
|
299
|
-
|
|
300
|
-
{
|
|
301
|
-
try {
|
|
302
|
-
digest = ethers.TypedDataEncoder.hash(
|
|
303
|
-
args.typedData.domain,
|
|
304
|
-
types,
|
|
305
|
-
args.typedData.message
|
|
306
|
-
);
|
|
307
|
-
} catch (e) {
|
|
308
|
-
if (ethers.isError(e, "INVALID_ARGUMENT")) {
|
|
309
|
-
reject(
|
|
310
|
-
new UWError("INVALID_REQUEST", `invalid typed data: ${e.message}`)
|
|
311
|
-
);
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
reject(e);
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
294
|
+
const digest = hashTypedData(typedData);
|
|
318
295
|
this.xConnection.setResponseHandler({
|
|
319
296
|
resolve: (resp) => {
|
|
320
297
|
this.xConnection.setResponseHandler(null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unwallet-client-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "unWallet client-side SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "SIVIRA",
|
|
@@ -29,23 +29,18 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"zod": "3.25.13"
|
|
32
|
+
"viem": "2.45.0",
|
|
33
|
+
"zod": "4.3.6"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
|
-
"@commitlint/cli": "
|
|
38
|
-
"@commitlint/config-conventional": "
|
|
39
|
-
"@commitlint/types": "
|
|
40
|
-
"@tsconfig/strictest": "2.0.
|
|
41
|
-
"@types/lodash": "4.17.17",
|
|
36
|
+
"@commitlint/cli": "20.3.1",
|
|
37
|
+
"@commitlint/config-conventional": "20.3.1",
|
|
38
|
+
"@commitlint/types": "20.3.1",
|
|
39
|
+
"@tsconfig/strictest": "2.0.8",
|
|
42
40
|
"commitizen": "4.3.1",
|
|
43
41
|
"cz-conventional-changelog": "3.3.0",
|
|
44
42
|
"husky": "9.1.7",
|
|
45
|
-
"tsup": "8.5.
|
|
43
|
+
"tsup": "8.5.1"
|
|
46
44
|
},
|
|
47
|
-
"scripts": {
|
|
48
|
-
"build": "tsup",
|
|
49
|
-
"commit": "cz"
|
|
50
|
-
}
|
|
45
|
+
"scripts": {}
|
|
51
46
|
}
|