viem 0.0.0-main.20230730T155828 → 0.0.0-main.20230731T075717
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/accounts/index.js +1 -1
- package/dist/cjs/accounts/index.js.map +1 -1
- package/dist/cjs/accounts/utils/signMessage.js +1 -1
- package/dist/cjs/accounts/utils/signMessage.js.map +1 -1
- package/dist/cjs/accounts/utils/signTypedData.js +1 -1
- package/dist/cjs/accounts/utils/signTypedData.js.map +1 -1
- package/dist/cjs/constants/number.js +101 -0
- package/dist/cjs/constants/number.js.map +1 -0
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js +110 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/signature/hexToSignature.js +12 -0
- package/dist/cjs/utils/signature/hexToSignature.js.map +1 -0
- package/dist/cjs/utils/signature/signatureToHex.js.map +1 -0
- package/dist/esm/accounts/index.js +1 -1
- package/dist/esm/accounts/index.js.map +1 -1
- package/dist/esm/accounts/utils/signMessage.js +1 -1
- package/dist/esm/accounts/utils/signMessage.js.map +1 -1
- package/dist/esm/accounts/utils/signTypedData.js +1 -1
- package/dist/esm/accounts/utils/signTypedData.js.map +1 -1
- package/dist/esm/constants/number.js +97 -0
- package/dist/esm/constants/number.js.map +1 -0
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/signature/hexToSignature.js +18 -0
- package/dist/esm/utils/signature/hexToSignature.js.map +1 -0
- package/dist/esm/utils/signature/signatureToHex.js +21 -0
- package/dist/esm/utils/signature/signatureToHex.js.map +1 -0
- package/dist/types/accounts/index.d.ts +1 -1
- package/dist/types/accounts/index.d.ts.map +1 -1
- package/dist/types/constants/number.d.ts +97 -0
- package/dist/types/constants/number.d.ts.map +1 -0
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/misc.d.ts.map +1 -1
- package/dist/types/utils/signature/hexToSignature.d.ts +13 -0
- package/dist/types/utils/signature/hexToSignature.d.ts.map +1 -0
- package/dist/types/utils/signature/signatureToHex.d.ts +17 -0
- package/dist/types/utils/signature/signatureToHex.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/accounts/index.ts +1 -1
- package/src/accounts/utils/signMessage.ts +1 -1
- package/src/accounts/utils/signTypedData.ts +1 -1
- package/src/constants/number.ts +98 -0
- package/src/errors/version.ts +1 -1
- package/src/index.ts +101 -1
- package/src/types/misc.ts +3 -0
- package/src/utils/signature/hexToSignature.ts +20 -0
- package/src/utils/signature/signatureToHex.ts +26 -0
- package/dist/cjs/accounts/utils/signatureToHex.js.map +0 -1
- package/dist/esm/accounts/utils/signatureToHex.js +0 -7
- package/dist/esm/accounts/utils/signatureToHex.js.map +0 -1
- package/dist/types/accounts/utils/signatureToHex.d.ts +0 -3
- package/dist/types/accounts/utils/signatureToHex.d.ts.map +0 -1
- package/src/accounts/utils/signatureToHex.ts +0 -12
- /package/dist/cjs/{accounts/utils → utils/signature}/signatureToHex.js +0 -0
package/src/index.ts
CHANGED
@@ -304,8 +304,106 @@ export {
|
|
304
304
|
webSocket,
|
305
305
|
} from './clients/transports/webSocket.js'
|
306
306
|
export { multicall3Abi } from './constants/abis.js'
|
307
|
-
export { etherUnits, gweiUnits, weiUnits } from './constants/unit.js'
|
308
307
|
export { zeroAddress } from './constants/address.js'
|
308
|
+
export { etherUnits, gweiUnits, weiUnits } from './constants/unit.js'
|
309
|
+
export {
|
310
|
+
maxInt8,
|
311
|
+
maxInt16,
|
312
|
+
maxInt24,
|
313
|
+
maxInt32,
|
314
|
+
maxInt40,
|
315
|
+
maxInt48,
|
316
|
+
maxInt56,
|
317
|
+
maxInt64,
|
318
|
+
maxInt72,
|
319
|
+
maxInt80,
|
320
|
+
maxInt88,
|
321
|
+
maxInt96,
|
322
|
+
maxInt104,
|
323
|
+
maxInt112,
|
324
|
+
maxInt120,
|
325
|
+
maxInt128,
|
326
|
+
maxInt136,
|
327
|
+
maxInt144,
|
328
|
+
maxInt152,
|
329
|
+
maxInt160,
|
330
|
+
maxInt168,
|
331
|
+
maxInt176,
|
332
|
+
maxInt184,
|
333
|
+
maxInt192,
|
334
|
+
maxInt200,
|
335
|
+
maxInt208,
|
336
|
+
maxInt216,
|
337
|
+
maxInt224,
|
338
|
+
maxInt232,
|
339
|
+
maxInt240,
|
340
|
+
maxInt248,
|
341
|
+
maxInt256,
|
342
|
+
maxUint8,
|
343
|
+
maxUint16,
|
344
|
+
maxUint24,
|
345
|
+
maxUint32,
|
346
|
+
maxUint40,
|
347
|
+
maxUint48,
|
348
|
+
maxUint56,
|
349
|
+
maxUint64,
|
350
|
+
maxUint72,
|
351
|
+
maxUint80,
|
352
|
+
maxUint88,
|
353
|
+
maxUint96,
|
354
|
+
maxUint104,
|
355
|
+
maxUint112,
|
356
|
+
maxUint120,
|
357
|
+
maxUint128,
|
358
|
+
maxUint136,
|
359
|
+
maxUint144,
|
360
|
+
maxUint152,
|
361
|
+
maxUint160,
|
362
|
+
maxUint168,
|
363
|
+
maxUint176,
|
364
|
+
maxUint184,
|
365
|
+
maxUint192,
|
366
|
+
maxUint200,
|
367
|
+
maxUint208,
|
368
|
+
maxUint216,
|
369
|
+
maxUint224,
|
370
|
+
maxUint232,
|
371
|
+
maxUint240,
|
372
|
+
maxUint248,
|
373
|
+
maxUint256,
|
374
|
+
minInt8,
|
375
|
+
minInt16,
|
376
|
+
minInt24,
|
377
|
+
minInt32,
|
378
|
+
minInt40,
|
379
|
+
minInt48,
|
380
|
+
minInt56,
|
381
|
+
minInt64,
|
382
|
+
minInt72,
|
383
|
+
minInt80,
|
384
|
+
minInt88,
|
385
|
+
minInt96,
|
386
|
+
minInt104,
|
387
|
+
minInt112,
|
388
|
+
minInt120,
|
389
|
+
minInt128,
|
390
|
+
minInt136,
|
391
|
+
minInt144,
|
392
|
+
minInt152,
|
393
|
+
minInt160,
|
394
|
+
minInt168,
|
395
|
+
minInt176,
|
396
|
+
minInt184,
|
397
|
+
minInt192,
|
398
|
+
minInt200,
|
399
|
+
minInt208,
|
400
|
+
minInt216,
|
401
|
+
minInt224,
|
402
|
+
minInt232,
|
403
|
+
minInt240,
|
404
|
+
minInt248,
|
405
|
+
minInt256,
|
406
|
+
} from './constants/number.js'
|
309
407
|
export {
|
310
408
|
AbiConstructorNotFoundError,
|
311
409
|
AbiConstructorParamsNotFoundError,
|
@@ -636,6 +734,7 @@ export {
|
|
636
734
|
type HashTypedDataReturnType,
|
637
735
|
hashTypedData,
|
638
736
|
} from './utils/signature/hashTypedData.js'
|
737
|
+
export { hexToSignature } from './utils/signature/hexToSignature.js'
|
639
738
|
export {
|
640
739
|
type RecoverAddressParameters,
|
641
740
|
type RecoverAddressReturnType,
|
@@ -656,6 +755,7 @@ export {
|
|
656
755
|
type RecoverTypedDataAddressReturnType,
|
657
756
|
recoverTypedDataAddress,
|
658
757
|
} from './utils/signature/recoverTypedDataAddress.js'
|
758
|
+
export { signatureToHex } from './utils/signature/signatureToHex.js'
|
659
759
|
export { type ToRlpReturnType, toRlp } from './utils/encoding/toRlp.js'
|
660
760
|
export {
|
661
761
|
type VerifyMessageParameters,
|
package/src/types/misc.ts
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
import { secp256k1 } from '@noble/curves/secp256k1'
|
2
|
+
|
3
|
+
import type { Hex, Signature } from '../../types/misc.js'
|
4
|
+
import { numberToHex } from '../../utils/encoding/toHex.js'
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @description Parses a hex formatted signature into a structured signature.
|
8
|
+
*
|
9
|
+
* @param signatureHex Signature in hex format.
|
10
|
+
* @returns The structured signature.
|
11
|
+
*
|
12
|
+
* @example
|
13
|
+
* hexToSignature('0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c')
|
14
|
+
* // { r: '0x...', s: '0x...', v: 28n }
|
15
|
+
*/
|
16
|
+
export function hexToSignature(signatureHex: Hex): Signature {
|
17
|
+
const { r, s } = secp256k1.Signature.fromCompact(signatureHex.slice(2, 130))
|
18
|
+
const v = BigInt(`0x${signatureHex.slice(130)}`)
|
19
|
+
return { r: numberToHex(r), s: numberToHex(s), v }
|
20
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { secp256k1 } from '@noble/curves/secp256k1'
|
2
|
+
|
3
|
+
import type { Hex, Signature } from '../../types/misc.js'
|
4
|
+
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
|
5
|
+
import { toHex } from '../../utils/encoding/toHex.js'
|
6
|
+
|
7
|
+
/**
|
8
|
+
* @description Converts a signature into hex format.
|
9
|
+
*
|
10
|
+
* @param signature The signature to convert.
|
11
|
+
* @returns The signature in hex format.
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* signatureToHex({
|
15
|
+
* r: '0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf',
|
16
|
+
* s: '0x4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8',
|
17
|
+
* v: 28n
|
18
|
+
* })
|
19
|
+
* // "0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c"
|
20
|
+
*/
|
21
|
+
export function signatureToHex({ r, s, v }: Signature): Hex {
|
22
|
+
return `0x${new secp256k1.Signature(
|
23
|
+
hexToBigInt(r),
|
24
|
+
hexToBigInt(s),
|
25
|
+
).toCompactHex()}${toHex(v).slice(2)}`
|
26
|
+
}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"signatureToHex.js","sourceRoot":"","sources":["../../../../src/accounts/utils/signatureToHex.ts"],"names":[],"mappings":";;;AAAA,uDAAmD;AAGnD,gEAA6D;AAC7D,4DAAqD;AAErD,SAAgB,cAAc,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAa;IACnD,OAAO,KAAK,IAAI,qBAAS,CAAC,SAAS,CACjC,IAAA,wBAAW,EAAC,CAAC,CAAC,EACd,IAAA,wBAAW,EAAC,CAAC,CAAC,CACf,CAAC,YAAY,EAAE,GAAG,IAAA,gBAAK,EAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;AACxC,CAAC;AALD,wCAKC"}
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import { secp256k1 } from '@noble/curves/secp256k1';
|
2
|
-
import { hexToBigInt } from '../../utils/encoding/fromHex.js';
|
3
|
-
import { toHex } from '../../utils/encoding/toHex.js';
|
4
|
-
export function signatureToHex({ r, s, v }) {
|
5
|
-
return `0x${new secp256k1.Signature(hexToBigInt(r), hexToBigInt(s)).toCompactHex()}${toHex(v).slice(2)}`;
|
6
|
-
}
|
7
|
-
//# sourceMappingURL=signatureToHex.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"signatureToHex.js","sourceRoot":"","sources":["../../../../src/accounts/utils/signatureToHex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAA;AAErD,MAAM,UAAU,cAAc,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAa;IACnD,OAAO,KAAK,IAAI,SAAS,CAAC,SAAS,CACjC,WAAW,CAAC,CAAC,CAAC,EACd,WAAW,CAAC,CAAC,CAAC,CACf,CAAC,YAAY,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;AACxC,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"signatureToHex.d.ts","sourceRoot":"","sources":["../../../../src/accounts/utils/signatureToHex.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAIzD,wBAAgB,cAAc,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,SAAS,GAAG,GAAG,CAK1D"}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { secp256k1 } from '@noble/curves/secp256k1'
|
2
|
-
|
3
|
-
import type { Hex, Signature } from '../../types/misc.js'
|
4
|
-
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
|
5
|
-
import { toHex } from '../../utils/encoding/toHex.js'
|
6
|
-
|
7
|
-
export function signatureToHex({ r, s, v }: Signature): Hex {
|
8
|
-
return `0x${new secp256k1.Signature(
|
9
|
-
hexToBigInt(r),
|
10
|
-
hexToBigInt(s),
|
11
|
-
).toCompactHex()}${toHex(v).slice(2)}`
|
12
|
-
}
|
File without changes
|