@api3/commons 1.0.0 → 1.0.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/dist/blockchain-utilities/schema.d.ts +3 -3
- package/dist/blockchain-utilities/schema.d.ts.map +1 -1
- package/dist/blockchain-utilities/schema.js +4 -3
- package/dist/blockchain-utilities/schema.js.map +1 -1
- package/package.json +1 -1
- package/src/blockchain-utilities/schema.test.ts +3 -0
- package/src/blockchain-utilities/schema.ts +4 -3
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export declare const hexSchema: z.ZodString
|
|
2
|
+
export declare const hexSchema: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
3
3
|
export type Hex = z.infer<typeof hexSchema>;
|
|
4
|
-
export declare const addressSchema: z.ZodPipe<z.ZodString, z.ZodTransform
|
|
4
|
+
export declare const addressSchema: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
5
5
|
export type Address = z.infer<typeof addressSchema>;
|
|
6
|
-
export declare const keccak256HashSchema: z.ZodPipe<z.ZodString, z.ZodTransform
|
|
6
|
+
export declare const keccak256HashSchema: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
7
7
|
export type Keccak256Hash = z.infer<typeof keccak256HashSchema>;
|
|
8
8
|
export declare const chainIdSchema: z.ZodString;
|
|
9
9
|
export type ChainId = z.infer<typeof chainIdSchema>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/blockchain-utilities/schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/blockchain-utilities/schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,SAAS,+DAGqB,CAAC;AAE5C,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAE5C,eAAO,MAAM,aAAa,+DAQxB,CAAC;AAEH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAEpD,eAAO,MAAM,mBAAmB,+DAGC,CAAC;AAElC,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,eAAO,MAAM,aAAa,aAGoD,CAAC;AAE/E,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAEpD,eAAO,MAAM,cAAc,oLAQzB,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAEtD,eAAO,MAAM,cAAc,aAEwD,CAAC;AAEpF,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -4,9 +4,10 @@ exports.mnemonicSchema = exports.ethUnitsSchema = exports.chainIdSchema = export
|
|
|
4
4
|
const promise_utils_1 = require("@api3/promise-utils");
|
|
5
5
|
const ethers_1 = require("ethers");
|
|
6
6
|
const zod_1 = require("zod");
|
|
7
|
-
exports.hexSchema = zod_1.z
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
exports.hexSchema = zod_1.z
|
|
8
|
+
.string()
|
|
9
|
+
.regex(/^0x[\dA-Fa-f]+$/, 'Invalid hex string format')
|
|
10
|
+
.transform((val) => val);
|
|
10
11
|
exports.addressSchema = zod_1.z.string().transform((value, ctx) => {
|
|
11
12
|
const goParseAddress = (0, promise_utils_1.goSync)(() => ethers_1.ethers.utils.getAddress(value));
|
|
12
13
|
if (!goParseAddress.success) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/blockchain-utilities/schema.ts"],"names":[],"mappings":";;;AAAA,uDAA6C;AAC7C,mCAAgC;AAChC,6BAAwB;AAEX,QAAA,SAAS,GAAG,OAAC,
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/blockchain-utilities/schema.ts"],"names":[],"mappings":";;;AAAA,uDAA6C;AAC7C,mCAAgC;AAChC,6BAAwB;AAEX,QAAA,SAAS,GAAG,OAAC;KACvB,MAAM,EAAE;KACR,KAAK,CAAC,iBAAiB,EAAE,2BAA2B,CAAC;KACrD,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAoB,CAAC,CAAC;AAI/B,QAAA,aAAa,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IAC/D,MAAM,cAAc,GAAG,IAAA,sBAAM,EAAC,GAAG,EAAE,CAAC,eAAM,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IACpE,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QAC5B,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAClF,OAAO,OAAC,CAAC,KAAK,CAAC;IACjB,CAAC;IAED,OAAO,cAAc,CAAC,IAAW,CAAC;AACpC,CAAC,CAAC,CAAC;AAIU,QAAA,mBAAmB,GAAG,OAAC;KACjC,MAAM,EAAE;KACR,KAAK,CAAC,oBAAoB,EAAE,oCAAoC,CAAC;KACjE,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAU,CAAC,CAAC;AAIrB,QAAA,aAAa,GAAG,OAAC;KAC3B,MAAM,EAAE;KACR,KAAK,CAAC,OAAO,EAAE,0BAA0B,CAAC;KAC1C,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,iCAAiC,CAAC,CAAC;AAIlE,QAAA,cAAc,GAAG,OAAC,CAAC,KAAK,CAAC;IACpC,OAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IAChB,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACjB,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACjB,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACjB,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IAClB,OAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IACnB,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC;CACnB,CAAC,CAAC;AAIU,QAAA,cAAc,GAAG,OAAC;KAC5B,MAAM,EAAE;KACR,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,eAAM,CAAC,KAAK,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,kBAAkB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -31,12 +31,15 @@ describe('keccak256HashSchema', () => {
|
|
|
31
31
|
describe('hexSchema', () => {
|
|
32
32
|
it('validates a valid hex string', () => {
|
|
33
33
|
expect(() => hexSchema.parse('0x3528e42b017a5fbf9d2993a2df04efc3ed474357575065a111b054ddf9de2acc')).not.toThrow();
|
|
34
|
+
expect(() => hexSchema.parse('0x3528e42b')).not.toThrow();
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
it('throws for an invalid hex string', () => {
|
|
37
38
|
expect(() => hexSchema.parse('3528e42b017a5fbf9d2993a2df04efc3ed474357575065a111b054ddf9de2acc')).toThrow(
|
|
38
39
|
expect.objectContaining({ name: 'ZodError' })
|
|
39
40
|
);
|
|
41
|
+
expect(() => hexSchema.parse('x3528e42b')).toThrow(expect.objectContaining({ name: 'ZodError' }));
|
|
42
|
+
expect(() => hexSchema.parse('')).toThrow(expect.objectContaining({ name: 'ZodError' }));
|
|
40
43
|
});
|
|
41
44
|
});
|
|
42
45
|
|
|
@@ -2,9 +2,10 @@ import { goSync } from '@api3/promise-utils';
|
|
|
2
2
|
import { ethers } from 'ethers';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
-
export const hexSchema = z
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export const hexSchema = z
|
|
6
|
+
.string()
|
|
7
|
+
.regex(/^0x[\dA-Fa-f]+$/, 'Invalid hex string format')
|
|
8
|
+
.transform((val) => val as `0x${string}`);
|
|
8
9
|
|
|
9
10
|
export type Hex = z.infer<typeof hexSchema>;
|
|
10
11
|
|