unwallet-client-sdk 0.17.0 → 0.18.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/README.md +1 -1
- package/dist/{index.mjs → index.cjs} +47 -47
- package/dist/{index.d.mts → index.d.cts} +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +24 -85
- package/package.json +11 -21
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# unWallet client-side SDK
|
|
2
2
|
|
|
3
|
-
[](https://npm.im/unwallet-client-sdk)
|
|
4
4
|
|
|
5
5
|
:warning: This SDK works correctly only on web browsers.
|
|
6
6
|
|
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
UWError: () => UWError,
|
|
24
|
+
UnWallet: () => UnWallet
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
1
28
|
// src/error.ts
|
|
2
29
|
var _UWError = class _UWError extends Error {
|
|
3
30
|
constructor(code, message) {
|
|
@@ -9,8 +36,7 @@ _UWError.prototype.name = "UWError";
|
|
|
9
36
|
var UWError = _UWError;
|
|
10
37
|
|
|
11
38
|
// src/unwallet.ts
|
|
12
|
-
|
|
13
|
-
import omit from "lodash/omit";
|
|
39
|
+
var import_viem = require("viem");
|
|
14
40
|
|
|
15
41
|
// src/config.ts
|
|
16
42
|
var UNWALLET_CONFIG_PROD = {
|
|
@@ -41,7 +67,7 @@ function getUnWalletConfigByEnv(env) {
|
|
|
41
67
|
}
|
|
42
68
|
|
|
43
69
|
// src/x.ts
|
|
44
|
-
|
|
70
|
+
var import_zod = require("zod");
|
|
45
71
|
var VALID_X_RESPONSE_TYPES = [
|
|
46
72
|
"connectionID",
|
|
47
73
|
"signature",
|
|
@@ -144,7 +170,7 @@ var XConnection = class _XConnection {
|
|
|
144
170
|
}
|
|
145
171
|
};
|
|
146
172
|
function safeParseMessageEventDataToXResponse(data) {
|
|
147
|
-
const result = z.string().refine(
|
|
173
|
+
const result = import_zod.z.string().refine(
|
|
148
174
|
(val) => {
|
|
149
175
|
try {
|
|
150
176
|
JSON.parse(val);
|
|
@@ -158,9 +184,9 @@ function safeParseMessageEventDataToXResponse(data) {
|
|
|
158
184
|
message: "Invalid JSON string"
|
|
159
185
|
}
|
|
160
186
|
).transform((val) => JSON.parse(val)).pipe(
|
|
161
|
-
z.object({
|
|
162
|
-
type: z.enum(VALID_X_RESPONSE_TYPES),
|
|
163
|
-
value: z.string()
|
|
187
|
+
import_zod.z.object({
|
|
188
|
+
type: import_zod.z.enum(VALID_X_RESPONSE_TYPES),
|
|
189
|
+
value: import_zod.z.string()
|
|
164
190
|
})
|
|
165
191
|
).safeParse(data);
|
|
166
192
|
if (!result.success) {
|
|
@@ -228,7 +254,7 @@ var UnWallet = class _UnWallet {
|
|
|
228
254
|
reject(new UWError("REQUEST_IN_PROGRESS"));
|
|
229
255
|
return;
|
|
230
256
|
}
|
|
231
|
-
const digest =
|
|
257
|
+
const digest = (0, import_viem.sha256)((0, import_viem.toBytes)(args.message));
|
|
232
258
|
this.xConnection.setResponseHandler({
|
|
233
259
|
resolve: (resp) => {
|
|
234
260
|
this.xConnection.setResponseHandler(null);
|
|
@@ -271,50 +297,23 @@ var UnWallet = class _UnWallet {
|
|
|
271
297
|
reject(new UWError("REQUEST_IN_PROGRESS"));
|
|
272
298
|
return;
|
|
273
299
|
}
|
|
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) {
|
|
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) {
|
|
291
308
|
reject(
|
|
292
309
|
new UWError(
|
|
293
310
|
"INVALID_REQUEST",
|
|
294
|
-
`invalid typed data:
|
|
311
|
+
`invalid typed data: ${e.message}`
|
|
295
312
|
)
|
|
296
313
|
);
|
|
297
314
|
return;
|
|
298
315
|
}
|
|
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
|
-
}
|
|
316
|
+
const digest = (0, import_viem.hashTypedData)(typedData);
|
|
318
317
|
this.xConnection.setResponseHandler({
|
|
319
318
|
resolve: (resp) => {
|
|
320
319
|
this.xConnection.setResponseHandler(null);
|
|
@@ -417,7 +416,8 @@ function openWindow(url) {
|
|
|
417
416
|
`width=${width},height=${height},left=${left},top=${top}`
|
|
418
417
|
);
|
|
419
418
|
}
|
|
420
|
-
export
|
|
419
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
420
|
+
0 && (module.exports = {
|
|
421
421
|
UWError,
|
|
422
422
|
UnWallet
|
|
423
|
-
};
|
|
423
|
+
});
|
|
@@ -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,40 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
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
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
UWError: () => UWError,
|
|
34
|
-
UnWallet: () => UnWallet
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(index_exports);
|
|
37
|
-
|
|
38
1
|
// src/error.ts
|
|
39
2
|
var _UWError = class _UWError extends Error {
|
|
40
3
|
constructor(code, message) {
|
|
@@ -46,8 +9,12 @@ _UWError.prototype.name = "UWError";
|
|
|
46
9
|
var UWError = _UWError;
|
|
47
10
|
|
|
48
11
|
// src/unwallet.ts
|
|
49
|
-
|
|
50
|
-
|
|
12
|
+
import {
|
|
13
|
+
hashTypedData,
|
|
14
|
+
toBytes,
|
|
15
|
+
sha256,
|
|
16
|
+
validateTypedData
|
|
17
|
+
} from "viem";
|
|
51
18
|
|
|
52
19
|
// src/config.ts
|
|
53
20
|
var UNWALLET_CONFIG_PROD = {
|
|
@@ -78,7 +45,7 @@ function getUnWalletConfigByEnv(env) {
|
|
|
78
45
|
}
|
|
79
46
|
|
|
80
47
|
// src/x.ts
|
|
81
|
-
|
|
48
|
+
import { z } from "zod";
|
|
82
49
|
var VALID_X_RESPONSE_TYPES = [
|
|
83
50
|
"connectionID",
|
|
84
51
|
"signature",
|
|
@@ -181,7 +148,7 @@ var XConnection = class _XConnection {
|
|
|
181
148
|
}
|
|
182
149
|
};
|
|
183
150
|
function safeParseMessageEventDataToXResponse(data) {
|
|
184
|
-
const result =
|
|
151
|
+
const result = z.string().refine(
|
|
185
152
|
(val) => {
|
|
186
153
|
try {
|
|
187
154
|
JSON.parse(val);
|
|
@@ -195,9 +162,9 @@ function safeParseMessageEventDataToXResponse(data) {
|
|
|
195
162
|
message: "Invalid JSON string"
|
|
196
163
|
}
|
|
197
164
|
).transform((val) => JSON.parse(val)).pipe(
|
|
198
|
-
|
|
199
|
-
type:
|
|
200
|
-
value:
|
|
165
|
+
z.object({
|
|
166
|
+
type: z.enum(VALID_X_RESPONSE_TYPES),
|
|
167
|
+
value: z.string()
|
|
201
168
|
})
|
|
202
169
|
).safeParse(data);
|
|
203
170
|
if (!result.success) {
|
|
@@ -265,7 +232,7 @@ var UnWallet = class _UnWallet {
|
|
|
265
232
|
reject(new UWError("REQUEST_IN_PROGRESS"));
|
|
266
233
|
return;
|
|
267
234
|
}
|
|
268
|
-
const digest =
|
|
235
|
+
const digest = sha256(toBytes(args.message));
|
|
269
236
|
this.xConnection.setResponseHandler({
|
|
270
237
|
resolve: (resp) => {
|
|
271
238
|
this.xConnection.setResponseHandler(null);
|
|
@@ -308,50 +275,23 @@ var UnWallet = class _UnWallet {
|
|
|
308
275
|
reject(new UWError("REQUEST_IN_PROGRESS"));
|
|
309
276
|
return;
|
|
310
277
|
}
|
|
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) {
|
|
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) {
|
|
328
286
|
reject(
|
|
329
287
|
new UWError(
|
|
330
288
|
"INVALID_REQUEST",
|
|
331
|
-
`invalid typed data:
|
|
289
|
+
`invalid typed data: ${e.message}`
|
|
332
290
|
)
|
|
333
291
|
);
|
|
334
292
|
return;
|
|
335
293
|
}
|
|
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
|
-
}
|
|
294
|
+
const digest = hashTypedData(typedData);
|
|
355
295
|
this.xConnection.setResponseHandler({
|
|
356
296
|
resolve: (resp) => {
|
|
357
297
|
this.xConnection.setResponseHandler(null);
|
|
@@ -454,8 +394,7 @@ function openWindow(url) {
|
|
|
454
394
|
`width=${width},height=${height},left=${left},top=${top}`
|
|
455
395
|
);
|
|
456
396
|
}
|
|
457
|
-
|
|
458
|
-
0 && (module.exports = {
|
|
397
|
+
export {
|
|
459
398
|
UWError,
|
|
460
399
|
UnWallet
|
|
461
|
-
}
|
|
400
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unwallet-client-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "unWallet client-side SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "SIVIRA",
|
|
@@ -22,30 +22,20 @@
|
|
|
22
22
|
"main": "dist/index.js",
|
|
23
23
|
"module": "dist/index.mjs",
|
|
24
24
|
"types": "dist/index.d.ts",
|
|
25
|
+
"type": "module",
|
|
25
26
|
"repository": "github:SIVIRA/unwallet-client-sdk-js",
|
|
26
|
-
"config": {
|
|
27
|
-
"commitizen": {
|
|
28
|
-
"path": "./node_modules/cz-conventional-changelog"
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
27
|
"dependencies": {
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"zod": "3.25.13"
|
|
28
|
+
"viem": "2.46.3",
|
|
29
|
+
"zod": "4.3.6"
|
|
35
30
|
},
|
|
36
31
|
"devDependencies": {
|
|
37
|
-
"@commitlint/cli": "
|
|
38
|
-
"@commitlint/config-conventional": "
|
|
39
|
-
"@commitlint/types": "
|
|
40
|
-
"@tsconfig/strictest": "2.0.
|
|
41
|
-
"
|
|
42
|
-
"commitizen": "4.3.1",
|
|
43
|
-
"cz-conventional-changelog": "3.3.0",
|
|
32
|
+
"@commitlint/cli": "20.4.2",
|
|
33
|
+
"@commitlint/config-conventional": "20.4.2",
|
|
34
|
+
"@commitlint/types": "20.4.0",
|
|
35
|
+
"@tsconfig/strictest": "2.0.8",
|
|
36
|
+
"czg": "1.12.0",
|
|
44
37
|
"husky": "9.1.7",
|
|
45
|
-
"tsup": "8.5.
|
|
38
|
+
"tsup": "8.5.1"
|
|
46
39
|
},
|
|
47
|
-
"scripts": {
|
|
48
|
-
"build": "tsup",
|
|
49
|
-
"commit": "cz"
|
|
50
|
-
}
|
|
40
|
+
"scripts": {}
|
|
51
41
|
}
|