unwallet-client-sdk 0.16.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 +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +83 -31
- package/dist/index.mjs +88 -31
- package/package.json +9 -12
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 {
|
|
@@ -9,6 +11,24 @@ interface UnWalletXAPIConfig {
|
|
|
9
11
|
connectionTimeout: number;
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
interface EIP712TypedData {
|
|
15
|
+
types: Record<string, Array<EIP712TypedDataField>>;
|
|
16
|
+
primaryType: string;
|
|
17
|
+
domain: EIP712TypedDataDomain;
|
|
18
|
+
message: Record<string, any>;
|
|
19
|
+
}
|
|
20
|
+
interface EIP712TypedDataDomain {
|
|
21
|
+
name?: string;
|
|
22
|
+
version?: string;
|
|
23
|
+
chainId?: number;
|
|
24
|
+
verifyingContract?: Address;
|
|
25
|
+
salt?: Hex;
|
|
26
|
+
}
|
|
27
|
+
interface EIP712TypedDataField {
|
|
28
|
+
name: string;
|
|
29
|
+
type: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
12
32
|
declare const VALID_UW_ERROR_CODES: readonly ["CONNECTION_TIMEOUT", "CONNECTION_FAILED", "CONNECTION_NOT_OPENED", "CONNECTION_CLOSED", "INVALID_REQUEST", "REQUEST_IN_PROGRESS", "REQUEST_REJECTED", "INVALID_RESPONSE"];
|
|
13
33
|
type UWErrorCode = (typeof VALID_UW_ERROR_CODES)[number];
|
|
14
34
|
declare class UWError extends Error {
|
|
@@ -72,6 +92,10 @@ declare class UnWallet {
|
|
|
72
92
|
message: string;
|
|
73
93
|
ticketToken: string;
|
|
74
94
|
}): Promise<SignResult>;
|
|
95
|
+
signEIP712TypedData(args: {
|
|
96
|
+
typedData: EIP712TypedData;
|
|
97
|
+
ticketToken: string;
|
|
98
|
+
}): Promise<SignResult>;
|
|
75
99
|
sendTransaction(args: {
|
|
76
100
|
chainID: number;
|
|
77
101
|
toAddress: string;
|
|
@@ -81,4 +105,4 @@ declare class UnWallet {
|
|
|
81
105
|
}): Promise<SendTransactionResult>;
|
|
82
106
|
}
|
|
83
107
|
|
|
84
|
-
export { type AuthorizationResponseMode, type Config, type Env, type SendTransactionResult, type SignResult, UWError, type UWErrorCode, UnWallet };
|
|
108
|
+
export { type AuthorizationResponseMode, type Config, type EIP712TypedData, type EIP712TypedDataDomain, type EIP712TypedDataField, type Env, type SendTransactionResult, type SignResult, UWError, type UWErrorCode, UnWallet };
|
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 {
|
|
@@ -9,6 +11,24 @@ interface UnWalletXAPIConfig {
|
|
|
9
11
|
connectionTimeout: number;
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
interface EIP712TypedData {
|
|
15
|
+
types: Record<string, Array<EIP712TypedDataField>>;
|
|
16
|
+
primaryType: string;
|
|
17
|
+
domain: EIP712TypedDataDomain;
|
|
18
|
+
message: Record<string, any>;
|
|
19
|
+
}
|
|
20
|
+
interface EIP712TypedDataDomain {
|
|
21
|
+
name?: string;
|
|
22
|
+
version?: string;
|
|
23
|
+
chainId?: number;
|
|
24
|
+
verifyingContract?: Address;
|
|
25
|
+
salt?: Hex;
|
|
26
|
+
}
|
|
27
|
+
interface EIP712TypedDataField {
|
|
28
|
+
name: string;
|
|
29
|
+
type: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
12
32
|
declare const VALID_UW_ERROR_CODES: readonly ["CONNECTION_TIMEOUT", "CONNECTION_FAILED", "CONNECTION_NOT_OPENED", "CONNECTION_CLOSED", "INVALID_REQUEST", "REQUEST_IN_PROGRESS", "REQUEST_REJECTED", "INVALID_RESPONSE"];
|
|
13
33
|
type UWErrorCode = (typeof VALID_UW_ERROR_CODES)[number];
|
|
14
34
|
declare class UWError extends Error {
|
|
@@ -72,6 +92,10 @@ declare class UnWallet {
|
|
|
72
92
|
message: string;
|
|
73
93
|
ticketToken: string;
|
|
74
94
|
}): Promise<SignResult>;
|
|
95
|
+
signEIP712TypedData(args: {
|
|
96
|
+
typedData: EIP712TypedData;
|
|
97
|
+
ticketToken: string;
|
|
98
|
+
}): Promise<SignResult>;
|
|
75
99
|
sendTransaction(args: {
|
|
76
100
|
chainID: number;
|
|
77
101
|
toAddress: string;
|
|
@@ -81,4 +105,4 @@ declare class UnWallet {
|
|
|
81
105
|
}): Promise<SendTransactionResult>;
|
|
82
106
|
}
|
|
83
107
|
|
|
84
|
-
export { type AuthorizationResponseMode, type Config, type Env, type SendTransactionResult, type SignResult, UWError, type UWErrorCode, UnWallet };
|
|
108
|
+
export { type AuthorizationResponseMode, type Config, type EIP712TypedData, type EIP712TypedDataDomain, type EIP712TypedDataField, type Env, type SendTransactionResult, type SignResult, UWError, type UWErrorCode, UnWallet };
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ _UWError.prototype.name = "UWError";
|
|
|
36
36
|
var UWError = _UWError;
|
|
37
37
|
|
|
38
38
|
// src/unwallet.ts
|
|
39
|
-
var
|
|
39
|
+
var import_viem = require("viem");
|
|
40
40
|
|
|
41
41
|
// src/config.ts
|
|
42
42
|
var UNWALLET_CONFIG_PROD = {
|
|
@@ -170,47 +170,37 @@ var XConnection = class _XConnection {
|
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
172
|
function safeParseMessageEventDataToXResponse(data) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const result = import_zod.z.string().refine((val) => {
|
|
173
|
+
const result = import_zod.z.string().refine(
|
|
174
|
+
(val) => {
|
|
176
175
|
try {
|
|
177
176
|
JSON.parse(val);
|
|
178
177
|
} catch (e) {
|
|
179
178
|
return false;
|
|
180
179
|
}
|
|
181
180
|
return true;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
error: new UWError(
|
|
187
|
-
"INVALID_RESPONSE",
|
|
188
|
-
"message event data must be a json string"
|
|
189
|
-
)
|
|
190
|
-
};
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
abort: true,
|
|
184
|
+
message: "Invalid JSON string"
|
|
191
185
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
let parsed;
|
|
195
|
-
{
|
|
196
|
-
const result = import_zod.z.object({
|
|
186
|
+
).transform((val) => JSON.parse(val)).pipe(
|
|
187
|
+
import_zod.z.object({
|
|
197
188
|
type: import_zod.z.enum(VALID_X_RESPONSE_TYPES),
|
|
198
189
|
value: import_zod.z.string()
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
parsed = result.data;
|
|
190
|
+
})
|
|
191
|
+
).safeParse(data);
|
|
192
|
+
if (!result.success) {
|
|
193
|
+
return {
|
|
194
|
+
success: false,
|
|
195
|
+
error: new UWError(
|
|
196
|
+
"INVALID_RESPONSE",
|
|
197
|
+
`invalid message event data: ${result.error.message}`
|
|
198
|
+
)
|
|
199
|
+
};
|
|
210
200
|
}
|
|
211
201
|
return {
|
|
212
202
|
success: true,
|
|
213
|
-
data:
|
|
203
|
+
data: result.data
|
|
214
204
|
};
|
|
215
205
|
}
|
|
216
206
|
|
|
@@ -264,6 +254,7 @@ var UnWallet = class _UnWallet {
|
|
|
264
254
|
reject(new UWError("REQUEST_IN_PROGRESS"));
|
|
265
255
|
return;
|
|
266
256
|
}
|
|
257
|
+
const digest = (0, import_viem.sha256)((0, import_viem.toBytes)(args.message));
|
|
267
258
|
this.xConnection.setResponseHandler({
|
|
268
259
|
resolve: (resp) => {
|
|
269
260
|
this.xConnection.setResponseHandler(null);
|
|
@@ -277,7 +268,7 @@ var UnWallet = class _UnWallet {
|
|
|
277
268
|
return;
|
|
278
269
|
}
|
|
279
270
|
resolve({
|
|
280
|
-
digest
|
|
271
|
+
digest,
|
|
281
272
|
signature: resp.value
|
|
282
273
|
});
|
|
283
274
|
},
|
|
@@ -296,6 +287,67 @@ var UnWallet = class _UnWallet {
|
|
|
296
287
|
openWindow(url);
|
|
297
288
|
});
|
|
298
289
|
}
|
|
290
|
+
signEIP712TypedData(args) {
|
|
291
|
+
return new Promise((resolve, reject) => {
|
|
292
|
+
if (this.xConnection.readyState !== WebSocket.OPEN) {
|
|
293
|
+
reject(new UWError("CONNECTION_NOT_OPENED"));
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (this.xConnection.hasResponseHandler) {
|
|
297
|
+
reject(new UWError("REQUEST_IN_PROGRESS"));
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
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) {
|
|
308
|
+
reject(
|
|
309
|
+
new UWError(
|
|
310
|
+
"INVALID_REQUEST",
|
|
311
|
+
`invalid typed data: ${e.message}`
|
|
312
|
+
)
|
|
313
|
+
);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const digest = (0, import_viem.hashTypedData)(typedData);
|
|
317
|
+
this.xConnection.setResponseHandler({
|
|
318
|
+
resolve: (resp) => {
|
|
319
|
+
this.xConnection.setResponseHandler(null);
|
|
320
|
+
if (resp.type !== "signature") {
|
|
321
|
+
reject(
|
|
322
|
+
new UWError(
|
|
323
|
+
"INVALID_RESPONSE",
|
|
324
|
+
`unexpected response type: ${resp.type}`
|
|
325
|
+
)
|
|
326
|
+
);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
resolve({
|
|
330
|
+
digest,
|
|
331
|
+
signature: resp.value
|
|
332
|
+
});
|
|
333
|
+
},
|
|
334
|
+
reject: (err) => {
|
|
335
|
+
this.xConnection.setResponseHandler(null);
|
|
336
|
+
reject(err);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
const url = new URL(
|
|
340
|
+
`${this.unWalletConfig.frontend.baseURL}/x/signEIP712TypedData`
|
|
341
|
+
);
|
|
342
|
+
{
|
|
343
|
+
url.searchParams.set("connectionID", this.xConnection.id);
|
|
344
|
+
url.searchParams.set("clientID", this.clientID);
|
|
345
|
+
url.searchParams.set("typedData", JSON.stringify(args.typedData));
|
|
346
|
+
url.searchParams.set("ticketToken", args.ticketToken);
|
|
347
|
+
}
|
|
348
|
+
openWindow(url);
|
|
349
|
+
});
|
|
350
|
+
}
|
|
299
351
|
sendTransaction(args) {
|
|
300
352
|
return new Promise((resolve, reject) => {
|
|
301
353
|
if (this.xConnection.readyState !== WebSocket.OPEN) {
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,12 @@ _UWError.prototype.name = "UWError";
|
|
|
9
9
|
var UWError = _UWError;
|
|
10
10
|
|
|
11
11
|
// src/unwallet.ts
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
hashTypedData,
|
|
14
|
+
toBytes,
|
|
15
|
+
sha256,
|
|
16
|
+
validateTypedData
|
|
17
|
+
} from "viem";
|
|
13
18
|
|
|
14
19
|
// src/config.ts
|
|
15
20
|
var UNWALLET_CONFIG_PROD = {
|
|
@@ -143,47 +148,37 @@ var XConnection = class _XConnection {
|
|
|
143
148
|
}
|
|
144
149
|
};
|
|
145
150
|
function safeParseMessageEventDataToXResponse(data) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const result = z.string().refine((val) => {
|
|
151
|
+
const result = z.string().refine(
|
|
152
|
+
(val) => {
|
|
149
153
|
try {
|
|
150
154
|
JSON.parse(val);
|
|
151
155
|
} catch (e) {
|
|
152
156
|
return false;
|
|
153
157
|
}
|
|
154
158
|
return true;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
error: new UWError(
|
|
160
|
-
"INVALID_RESPONSE",
|
|
161
|
-
"message event data must be a json string"
|
|
162
|
-
)
|
|
163
|
-
};
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
abort: true,
|
|
162
|
+
message: "Invalid JSON string"
|
|
164
163
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
let parsed;
|
|
168
|
-
{
|
|
169
|
-
const result = z.object({
|
|
164
|
+
).transform((val) => JSON.parse(val)).pipe(
|
|
165
|
+
z.object({
|
|
170
166
|
type: z.enum(VALID_X_RESPONSE_TYPES),
|
|
171
167
|
value: z.string()
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
parsed = result.data;
|
|
168
|
+
})
|
|
169
|
+
).safeParse(data);
|
|
170
|
+
if (!result.success) {
|
|
171
|
+
return {
|
|
172
|
+
success: false,
|
|
173
|
+
error: new UWError(
|
|
174
|
+
"INVALID_RESPONSE",
|
|
175
|
+
`invalid message event data: ${result.error.message}`
|
|
176
|
+
)
|
|
177
|
+
};
|
|
183
178
|
}
|
|
184
179
|
return {
|
|
185
180
|
success: true,
|
|
186
|
-
data:
|
|
181
|
+
data: result.data
|
|
187
182
|
};
|
|
188
183
|
}
|
|
189
184
|
|
|
@@ -237,6 +232,7 @@ var UnWallet = class _UnWallet {
|
|
|
237
232
|
reject(new UWError("REQUEST_IN_PROGRESS"));
|
|
238
233
|
return;
|
|
239
234
|
}
|
|
235
|
+
const digest = sha256(toBytes(args.message));
|
|
240
236
|
this.xConnection.setResponseHandler({
|
|
241
237
|
resolve: (resp) => {
|
|
242
238
|
this.xConnection.setResponseHandler(null);
|
|
@@ -250,7 +246,7 @@ var UnWallet = class _UnWallet {
|
|
|
250
246
|
return;
|
|
251
247
|
}
|
|
252
248
|
resolve({
|
|
253
|
-
digest
|
|
249
|
+
digest,
|
|
254
250
|
signature: resp.value
|
|
255
251
|
});
|
|
256
252
|
},
|
|
@@ -269,6 +265,67 @@ var UnWallet = class _UnWallet {
|
|
|
269
265
|
openWindow(url);
|
|
270
266
|
});
|
|
271
267
|
}
|
|
268
|
+
signEIP712TypedData(args) {
|
|
269
|
+
return new Promise((resolve, reject) => {
|
|
270
|
+
if (this.xConnection.readyState !== WebSocket.OPEN) {
|
|
271
|
+
reject(new UWError("CONNECTION_NOT_OPENED"));
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (this.xConnection.hasResponseHandler) {
|
|
275
|
+
reject(new UWError("REQUEST_IN_PROGRESS"));
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
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) {
|
|
286
|
+
reject(
|
|
287
|
+
new UWError(
|
|
288
|
+
"INVALID_REQUEST",
|
|
289
|
+
`invalid typed data: ${e.message}`
|
|
290
|
+
)
|
|
291
|
+
);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const digest = hashTypedData(typedData);
|
|
295
|
+
this.xConnection.setResponseHandler({
|
|
296
|
+
resolve: (resp) => {
|
|
297
|
+
this.xConnection.setResponseHandler(null);
|
|
298
|
+
if (resp.type !== "signature") {
|
|
299
|
+
reject(
|
|
300
|
+
new UWError(
|
|
301
|
+
"INVALID_RESPONSE",
|
|
302
|
+
`unexpected response type: ${resp.type}`
|
|
303
|
+
)
|
|
304
|
+
);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
resolve({
|
|
308
|
+
digest,
|
|
309
|
+
signature: resp.value
|
|
310
|
+
});
|
|
311
|
+
},
|
|
312
|
+
reject: (err) => {
|
|
313
|
+
this.xConnection.setResponseHandler(null);
|
|
314
|
+
reject(err);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
const url = new URL(
|
|
318
|
+
`${this.unWalletConfig.frontend.baseURL}/x/signEIP712TypedData`
|
|
319
|
+
);
|
|
320
|
+
{
|
|
321
|
+
url.searchParams.set("connectionID", this.xConnection.id);
|
|
322
|
+
url.searchParams.set("clientID", this.clientID);
|
|
323
|
+
url.searchParams.set("typedData", JSON.stringify(args.typedData));
|
|
324
|
+
url.searchParams.set("ticketToken", args.ticketToken);
|
|
325
|
+
}
|
|
326
|
+
openWindow(url);
|
|
327
|
+
});
|
|
328
|
+
}
|
|
272
329
|
sendTransaction(args) {
|
|
273
330
|
return new Promise((resolve, reject) => {
|
|
274
331
|
if (this.xConnection.readyState !== WebSocket.OPEN) {
|
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,21 +29,18 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"
|
|
33
|
-
"zod": "3.
|
|
32
|
+
"viem": "2.45.0",
|
|
33
|
+
"zod": "4.3.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@commitlint/cli": "
|
|
37
|
-
"@commitlint/config-conventional": "
|
|
38
|
-
"@commitlint/types": "
|
|
39
|
-
"@tsconfig/strictest": "2.0.
|
|
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",
|
|
40
40
|
"commitizen": "4.3.1",
|
|
41
41
|
"cz-conventional-changelog": "3.3.0",
|
|
42
42
|
"husky": "9.1.7",
|
|
43
|
-
"tsup": "8.
|
|
43
|
+
"tsup": "8.5.1"
|
|
44
44
|
},
|
|
45
|
-
"scripts": {
|
|
46
|
-
"build": "tsup",
|
|
47
|
-
"commit": "cz"
|
|
48
|
-
}
|
|
45
|
+
"scripts": {}
|
|
49
46
|
}
|