@api3/commons 0.4.1 → 0.6.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.
Files changed (33) hide show
  1. package/README.md +6 -4
  2. package/dist/blockchain-utilities/derivation.d.ts +78 -0
  3. package/dist/blockchain-utilities/derivation.d.ts.map +1 -0
  4. package/dist/blockchain-utilities/derivation.js +97 -0
  5. package/dist/blockchain-utilities/derivation.js.map +1 -0
  6. package/dist/blockchain-utilities/schema.d.ts +12 -0
  7. package/dist/blockchain-utilities/schema.d.ts.map +1 -0
  8. package/dist/blockchain-utilities/schema.js +13 -0
  9. package/dist/blockchain-utilities/schema.js.map +1 -0
  10. package/dist/processing/processing.d.ts +70 -18
  11. package/dist/processing/processing.d.ts.map +1 -1
  12. package/dist/processing/processing.js +145 -37
  13. package/dist/processing/processing.js.map +1 -1
  14. package/dist/processing/schema.d.ts +25 -2
  15. package/dist/processing/schema.d.ts.map +1 -1
  16. package/dist/processing/schema.js +10 -9
  17. package/dist/processing/schema.js.map +1 -1
  18. package/dist/processing/unsafe-evaluate.d.ts +1 -0
  19. package/dist/processing/unsafe-evaluate.d.ts.map +1 -1
  20. package/dist/processing/unsafe-evaluate.js +31 -1
  21. package/dist/processing/unsafe-evaluate.js.map +1 -1
  22. package/package.json +6 -4
  23. package/src/blockchain-utilities/README.md +5 -0
  24. package/src/blockchain-utilities/derivation.test.ts +147 -0
  25. package/src/blockchain-utilities/derivation.ts +116 -0
  26. package/src/blockchain-utilities/schema.test.ts +23 -0
  27. package/src/blockchain-utilities/schema.ts +14 -0
  28. package/src/processing/README.md +89 -14
  29. package/src/processing/processing.test.ts +431 -113
  30. package/src/processing/processing.ts +196 -47
  31. package/src/processing/schema.ts +21 -8
  32. package/src/processing/unsafe-evaluate.test.ts +220 -1
  33. package/src/processing/unsafe-evaluate.ts +39 -0
@@ -1 +1 @@
1
- {"version":3,"file":"processing.js","sourceRoot":"","sources":["../../src/processing/processing.ts"],"names":[],"m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BAA4B,EAAE,GAAG,QAAQ,CAAC;IACjF,IAAI,6BAA6B,EAAE;QACjC,OAAO,IAAA,6BAAqB,EAAC,QAAQ,EAAE,6BAA6B,EAAE,kBAAkB,CAAC,CAAC;KAC3F;IAED,MAAM,qBAAqB,GAAG,MAAM,IAAA,6BAAqB,EACvD,QAAQ,EACR,4BAA4B,EAC5B,kBAAkB,EAClB,iBAAiB,CAClB,CAAC;IACF,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,CAAC;AAC7C,CAAC,CAAC;AAlBW,QAAA,mBAAmB,uBAkB9B"}
@@ -1,3 +1,26 @@
1
- export declare const validateApiCallParameters: (apiCallParameters: unknown) => ApiCallParameters;
2
- export type ApiCallParameters = Record<string, any>;
1
+ import type { processingSpecificationSchemaV2, ProcessingSpecification } from '@api3/ois';
2
+ import { z } from 'zod';
3
+ export type ProcessingSpecificationV2 = z.infer<typeof processingSpecificationSchemaV2>;
4
+ export type ProcessingSpecifications = ProcessingSpecification[];
5
+ export declare const endpointParametersSchema: z.ZodRecord<z.ZodString, z.ZodAny>;
6
+ export type EndpointParameters = z.infer<typeof endpointParametersSchema>;
7
+ export declare const preProcessingV2ResponseSchema: z.ZodObject<{
8
+ endpointParameters: z.ZodRecord<z.ZodString, z.ZodAny>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ endpointParameters: Record<string, any>;
11
+ }, {
12
+ endpointParameters: Record<string, any>;
13
+ }>;
14
+ export type PreProcessingV2Response = z.infer<typeof preProcessingV2ResponseSchema>;
15
+ export declare const postProcessingV2ResponseSchema: z.ZodObject<{
16
+ response: z.ZodAny;
17
+ timestamp: z.ZodOptional<z.ZodNumber>;
18
+ }, "strip", z.ZodTypeAny, {
19
+ response?: any;
20
+ timestamp?: number | undefined;
21
+ }, {
22
+ response?: any;
23
+ timestamp?: number | undefined;
24
+ }>;
25
+ export type PostProcessingV2Response = z.infer<typeof postProcessingV2ResponseSchema>;
3
26
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/processing/schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,sBAAuB,OAAO,KAAG,iBAOtE,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/processing/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAC1F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC;AAExF,MAAM,MAAM,wBAAwB,GAAG,uBAAuB,EAAE,CAAC;AAEjE,eAAO,MAAM,wBAAwB,oCAAoB,CAAC;AAE1D,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E,eAAO,MAAM,6BAA6B;;;;;;EAExC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAEpF,eAAO,MAAM,8BAA8B;;;;;;;;;EAGzC,CAAC;AAEH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC"}
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateApiCallParameters = void 0;
4
- const validateApiCallParameters = (apiCallParameters) => {
5
- // eslint-disable-next-line lodash/prefer-lodash-typecheck
6
- if (typeof apiCallParameters !== 'object' || apiCallParameters === null) {
7
- throw new TypeError('Invalid API call parameters');
8
- }
9
- return apiCallParameters;
10
- };
11
- exports.validateApiCallParameters = validateApiCallParameters;
3
+ exports.postProcessingV2ResponseSchema = exports.preProcessingV2ResponseSchema = exports.endpointParametersSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.endpointParametersSchema = zod_1.z.record(zod_1.z.any());
6
+ exports.preProcessingV2ResponseSchema = zod_1.z.object({
7
+ endpointParameters: exports.endpointParametersSchema,
8
+ });
9
+ exports.postProcessingV2ResponseSchema = zod_1.z.object({
10
+ response: zod_1.z.any(),
11
+ timestamp: zod_1.z.number().nonnegative().int().optional(),
12
+ });
12
13
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/processing/schema.ts"],"names":[],"mappings":";;;AAAO,MAAM,yBAAyB,GAAG,CAAC,iBAA0B,EAAqB,EAAE;IACzF,0DAA0D;IAC1D,IAAI,OAAO,iBAAiB,KAAK,QAAQ,IAAI,iBAAiB,KAAK,IAAI,EAAE;QACvE,MAAM,IAAI,SAAS,CAAC,6BAA6B,CAAC,CAAC;KACpD;IAED,OAAO,iBAAsC,CAAC;AAChD,CAAC,CAAC;AAPW,QAAA,yBAAyB,6BAOpC"}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/processing/schema.ts"],"names":[],"mappings":";;;AACA,6BAAwB;AAMX,QAAA,wBAAwB,GAAG,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,GAAG,EAAE,CAAC,CAAC;AAI7C,QAAA,6BAA6B,GAAG,OAAC,CAAC,MAAM,CAAC;IACpD,kBAAkB,EAAE,gCAAwB;CAC7C,CAAC,CAAC;AAIU,QAAA,8BAA8B,GAAG,OAAC,CAAC,MAAM,CAAC;IACrD,QAAQ,EAAE,OAAC,CAAC,GAAG,EAAE;IACjB,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;CACrD,CAAC,CAAC"}
@@ -20,6 +20,7 @@
20
20
  *console.log(result); // Outputs: 2
21
21
  */
22
22
  export declare const unsafeEvaluate: (code: string, globalVariables: Record<string, unknown>, timeout: number) => unknown;
23
+ export declare const unsafeEvaluateV2: (code: string, payload: unknown, timeout: number) => Promise<any>;
23
24
  /**
24
25
  * Asynchronously evaluates the provided code in a new VM context with the specified global variables.
25
26
  *
@@ -1 +1 @@
1
- {"version":3,"file":"unsafe-evaluate.d.ts","sourceRoot":"","sources":["../../src/processing/unsafe-evaluate.ts"],"names":[],"mappings":"AA+EA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,SAAU,MAAM,mBAAmB,OAAO,MAAM,EAAE,OAAO,CAAC,WAAW,MAAM,YAarG,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,mBAAmB,SAAgB,MAAM,mBAAmB,OAAO,MAAM,EAAE,OAAO,CAAC,WAAW,MAAM,qBAoChH,CAAC"}
1
+ {"version":3,"file":"unsafe-evaluate.d.ts","sourceRoot":"","sources":["../../src/processing/unsafe-evaluate.ts"],"names":[],"mappings":"AAiFA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,SAAU,MAAM,mBAAmB,OAAO,MAAM,EAAE,OAAO,CAAC,WAAW,MAAM,YAarG,CAAC;AAEF,eAAO,MAAM,gBAAgB,SAAgB,MAAM,WAAW,OAAO,WAAW,MAAM,iBAmCrF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,mBAAmB,SAAgB,MAAM,mBAAmB,OAAO,MAAM,EAAE,OAAO,CAAC,WAAW,MAAM,qBAoChH,CAAC"}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.unsafeEvaluateAsync = exports.unsafeEvaluate = void 0;
6
+ exports.unsafeEvaluateAsync = exports.unsafeEvaluateV2 = exports.unsafeEvaluate = void 0;
7
7
  /* eslint-disable camelcase */
8
8
  const node_assert_1 = __importDefault(require("node:assert"));
9
9
  const node_async_hooks_1 = __importDefault(require("node:async_hooks"));
@@ -41,6 +41,7 @@ const node_v8_1 = __importDefault(require("node:v8"));
41
41
  const node_vm_1 = __importDefault(require("node:vm"));
42
42
  const node_worker_threads_1 = __importDefault(require("node:worker_threads"));
43
43
  const node_zlib_1 = __importDefault(require("node:zlib"));
44
+ const promise_utils_1 = require("@api3/promise-utils");
44
45
  const vm_timers_1 = require("./vm-timers");
45
46
  const builtInNodeModules = {
46
47
  assert: node_assert_1.default,
@@ -114,6 +115,35 @@ const unsafeEvaluate = (code, globalVariables, timeout) => {
114
115
  return vmContext.deferredOutput;
115
116
  };
116
117
  exports.unsafeEvaluate = unsafeEvaluate;
118
+ const unsafeEvaluateV2 = async (code, payload, timeout) => {
119
+ const timers = (0, vm_timers_1.createTimers)();
120
+ const goEvaluate = await (0, promise_utils_1.go)(
121
+ // eslint-disable-next-line @typescript-eslint/require-await
122
+ async () => node_vm_1.default.runInNewContext(`
123
+ (async () => {
124
+ return await (${code})(payload)
125
+ })();
126
+ `, {
127
+ ...builtInNodeModules,
128
+ setTimeout: timers.customSetTimeout,
129
+ setInterval: timers.customSetInterval,
130
+ clearTimeout: timers.customClearTimeout,
131
+ clearInterval: timers.customClearInterval,
132
+ payload,
133
+ }, { displayErrors: true, timeout }),
134
+ // Make sure the timeout is applied. When the processing snippet uses setTimeout or setInterval, the timeout option
135
+ // from VM is broken. See: https://github.com/nodejs/node/issues/3020.
136
+ { totalTimeoutMs: timeout });
137
+ // We need to manually clear all timers and reject the processing manually.
138
+ timers.clearAll();
139
+ if (goEvaluate.success) {
140
+ return goEvaluate.data;
141
+ }
142
+ else {
143
+ throw goEvaluate.error.reason ?? goEvaluate.error;
144
+ }
145
+ };
146
+ exports.unsafeEvaluateV2 = unsafeEvaluateV2;
117
147
  /**
118
148
  * Asynchronously evaluates the provided code in a new VM context with the specified global variables.
119
149
  *
@@ -1 +1 @@
1
- {"version":3,"file":"unsafe-evaluate.js","sourceRoot":"","sources":["../../src/processing/unsafe-evaluate.ts"],"names":[],"mappings":";;;;;;AAAA,8BAA8B;AAC9B,8DAAiC;AACjC,wEAA2C;AAC3C,8DAAiC;AACjC,4EAA+C;AAC/C,gEAAmC;AACnC,gEAAmC;AACnC,oEAAuC;AACvC,8DAAiC;AACjC,4DAA+B;AAC/B,wDAA2B;AAC3B,8DAAiC;AACjC,sDAAyB;AACzB,0DAA6B;AAC7B,4DAA+B;AAC/B,4DAA+B;AAC/B,oEAAuC;AACvC,8DAAiC;AACjC,wDAA2B;AAC3B,sDAAyB;AACzB,0DAA6B;AAC7B,sEAAyC;AACzC,gEAAmC;AACnC,kEAAqC;AACrC,0DAA6B;AAC7B,8DAAiC;AACjC,8EAAiD;AACjD,8DAAiC;AACjC,wDAA2B;AAC3B,0EAA6C;AAC7C,wDAA2B;AAC3B,wDAA2B;AAC3B,0DAA6B;AAC7B,sDAAyB;AACzB,sDAAyB;AACzB,8EAAiD;AACjD,0DAA6B;AAE7B,2CAA2C;AAE3C,MAAM,kBAAkB,GAAG;IACzB,MAAM,EAAN,qBAAM;IACN,WAAW,EAAX,0BAAW;IACX,MAAM,EAAN,qBAAM;IACN,aAAa,EAAb,4BAAa;IACb,OAAO,EAAP,sBAAO;IACP,OAAO,EAAP,sBAAO;IACP,SAAS,EAAT,wBAAS;IACT,MAAM,EAAN,qBAAM;IACN,KAAK,EAAL,oBAAK;IACL,GAAG,EAAH,kBAAG;IACH,MAAM,EAAN,qBAAM;IACN,EAAE,EAAF,iBAAE;IACF,IAAI,EAAJ,mBAAI;IACJ,KAAK,EAAL,oBAAK;IACL,KAAK,EAAL,oBAAK;IACL,SAAS,EAAT,wBAAS;IACT,MAAM,EAAN,qBAAM;IACN,GAAG,EAAH,kBAAG;IACH,EAAE,EAAF,iBAAE;IACF,IAAI,EAAJ,mBAAI;IACJ,UAAU,EAAV,yBAAU;IACV,OA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AC;AACL,CAAC,CAAC;AApCW,QAAA,mBAAmB,uBAoC9B"}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@api3/commons",
3
- "version": "0.4.1",
3
+ "version": "0.6.0",
4
4
  "keywords": [],
5
5
  "license": "MIT",
6
6
  "engines": {
7
- "node": "^18.14.0",
7
+ "node": "^18.14.0 || ^20.10.0",
8
8
  "pnpm": "^8.8.0"
9
9
  },
10
10
  "files": [
@@ -14,7 +14,7 @@
14
14
  "main": "./dist/index.js",
15
15
  "exports": "./dist/index.js",
16
16
  "dependencies": {
17
- "@api3/ois": "^2.2.1",
17
+ "@api3/ois": "^2.3.0",
18
18
  "@api3/promise-utils": "^0.4.0",
19
19
  "@typescript-eslint/eslint-plugin": "^6.2.1",
20
20
  "@typescript-eslint/parser": "^6.2.1",
@@ -32,9 +32,11 @@
32
32
  "eslint-plugin-react": "^7.32.1",
33
33
  "eslint-plugin-react-hooks": "^4.6.0",
34
34
  "eslint-plugin-unicorn": "^48.0.1",
35
+ "ethers": "^5.7.2",
35
36
  "lodash": "^4.17.21",
36
37
  "winston": "^3.10.0",
37
- "winston-console-format": "^1.0.8"
38
+ "winston-console-format": "^1.0.8",
39
+ "zod": "^3.22.4"
38
40
  },
39
41
  "devDependencies": {
40
42
  "@types/jest": "^29.5.5",
@@ -0,0 +1,5 @@
1
+ # Blockchain Utilities
2
+
3
+ ## A set of blockchain-related utility functions that are commonly used by API3 applications
4
+
5
+ Refer to the per-function documentation.
@@ -0,0 +1,147 @@
1
+ import { ethers } from 'ethers';
2
+
3
+ import {
4
+ deriveAirnodeXpub,
5
+ deriveBeaconId,
6
+ deriveBeaconSetId,
7
+ deriveEndpointId,
8
+ deriveSponsorWallet,
9
+ deriveTemplateId,
10
+ deriveWalletPathFromSponsorAddress,
11
+ fromBytes32String,
12
+ PROTOCOL_IDS,
13
+ toBytes32String,
14
+ } from './derivation';
15
+
16
+ describe('deriveWalletPathFromSponsorAddress', () => {
17
+ it('converts address to derivation path', () => {
18
+ const sponsorAddress = '0x8A45eac0267dD0803Fd957723EdE10693A076698';
19
+ const res = deriveWalletPathFromSponsorAddress(sponsorAddress, PROTOCOL_IDS.AIRSEEKER);
20
+ expect(res).toBe('5/973563544/2109481170/2137349576/871269377/610184194/17');
21
+
22
+ const randomAddress = ethers.utils.getAddress(ethers.utils.hexlify(ethers.utils.randomBytes(20)));
23
+ const randomPath = deriveWalletPathFromSponsorAddress(randomAddress, PROTOCOL_IDS.AIRSEEKER);
24
+ expect(res).not.toStrictEqual(randomPath);
25
+ });
26
+
27
+ it('converts zero address to derivation path', () => {
28
+ const sponsorAddress = ethers.constants.AddressZero;
29
+ const res = deriveWalletPathFromSponsorAddress(sponsorAddress, PROTOCOL_IDS.AIRSEEKER);
30
+ expect(res).toBe('5/0/0/0/0/0/0');
31
+ });
32
+
33
+ it('throws if address is null', () => {
34
+ const sponsorAddress = null;
35
+ expect(() => deriveWalletPathFromSponsorAddress(sponsorAddress!, PROTOCOL_IDS.AIRSEEKER)).toThrow(
36
+ expect.objectContaining({ name: expect.stringContaining('Error') })
37
+ );
38
+ });
39
+
40
+ it('throws if address is undefined', () => {
41
+ const sponsorAddress = undefined;
42
+ expect(() => deriveWalletPathFromSponsorAddress(sponsorAddress!, PROTOCOL_IDS.AIRSEEKER)).toThrow(
43
+ expect.objectContaining({ name: expect.stringContaining('Error') })
44
+ );
45
+ });
46
+
47
+ it('throws if address is an empty string', () => {
48
+ const sponsorAddress = '';
49
+ expect(() => deriveWalletPathFromSponsorAddress(sponsorAddress, PROTOCOL_IDS.AIRSEEKER)).toThrow(
50
+ expect.objectContaining({ name: expect.stringContaining('Error') })
51
+ );
52
+ });
53
+
54
+ it('throws if address is invalid', () => {
55
+ let sponsorAddress = '7dD0803Fd957723EdE10693A076698';
56
+ expect(() => deriveWalletPathFromSponsorAddress(sponsorAddress, PROTOCOL_IDS.AIRSEEKER)).toThrow(
57
+ expect.objectContaining({ name: expect.stringContaining('Error') })
58
+ );
59
+
60
+ sponsorAddress = ethers.utils.hexlify(ethers.utils.randomBytes(4));
61
+ expect(() => deriveWalletPathFromSponsorAddress(sponsorAddress, PROTOCOL_IDS.AIRSEEKER)).toThrow(
62
+ expect.objectContaining({ name: expect.stringContaining('Error') })
63
+ );
64
+
65
+ sponsorAddress = ethers.utils.hexlify(ethers.utils.randomBytes(32));
66
+ expect(() => deriveWalletPathFromSponsorAddress(sponsorAddress, PROTOCOL_IDS.AIRSEEKER)).toThrow(
67
+ expect.objectContaining({ name: expect.stringContaining('Error') })
68
+ );
69
+ });
70
+
71
+ describe('blockchain utilities', () => {
72
+ it('derives a sponsor wallet', () => {
73
+ const dapiName = ethers.utils.formatBytes32String('BTC/ETH');
74
+ const sponsorWallet = deriveSponsorWallet(
75
+ 'test test test test test test test test test test test junk',
76
+ dapiName
77
+ );
78
+
79
+ expect(sponsorWallet.address).toBe('0x1e6f0dfb1775f5032f12f56a01526351eD3F07aF');
80
+ });
81
+
82
+ it('throws deriving a sponsor wallet due to an invalid DApi name', () => {
83
+ const dapiName = 'invalid dapi name';
84
+ const throwingFn = () =>
85
+ deriveSponsorWallet('test test test test test test test test test test test junk', dapiName);
86
+
87
+ expect(throwingFn).toThrow(expect.objectContaining({ name: expect.stringContaining('Error') }));
88
+ });
89
+
90
+ it(`derives an airnode's xpub from a mnemonic`, () => {
91
+ const xpub = deriveAirnodeXpub('test test test test test test test test test test test junk');
92
+
93
+ expect(xpub).toBe(
94
+ 'xpub6Ce9NcJvTk36xtLSrJLZqE7wtgA5deCeYs7rSQtreh4cj6ByPtrg9sD7V2FNFLPnf8heNP3FGkeV9qwfzvZNSd54JoNXVsXFYSYwHsnJxqP'
95
+ );
96
+ });
97
+
98
+ it(`derives an endpoint ID`, () => {
99
+ const endpointId = deriveEndpointId('weather', 'temperature');
100
+
101
+ expect(endpointId).toBe('0x5a82d40e44ecd3ef0906e9e82c1a20f2f4ffe4f613ac70f999047496a9cd4635');
102
+ });
103
+
104
+ it(`it derives a template ID`, () => {
105
+ const templateId = deriveTemplateId({
106
+ airnode: '0x4E95C31894a89CdC4288669A6F294836948c862b',
107
+ endpointId: '0x5a82d40e44ecd3ef0906e9e82c1a20f2f4ffe4f613ac70f999047496a9cd4635',
108
+ encodedParameters: '0x1234',
109
+ });
110
+
111
+ expect(templateId).toBe('0x7655363f294273f84bcc7c47d79858cf46f21951deee92746d9f17a69ac0b0c0');
112
+ });
113
+
114
+ it('derives a beacon ID', () => {
115
+ const beaconId = deriveBeaconId(
116
+ '0xc52EeA00154B4fF1EbbF8Ba39FDe37F1AC3B9Fd4',
117
+ '0x457a3b3da67e394a895ea49e534a4d91b2d009477bef15eab8cbed313925b010'
118
+ );
119
+
120
+ expect(beaconId).toBe('0xf5c140bcb4814dfec311d38f6293e86c02d32ba1b7da027fe5b5202cae35dbc6');
121
+ });
122
+
123
+ it(`derives a beacon set ID`, () => {
124
+ const beaconSetId = deriveBeaconSetId([
125
+ '0x0e30ed302a3c8eeaa0053caf5fbd0825c86ce1767584d12c69c310f0068b1176',
126
+ '0x496092597aef79595df1567412c6ddefd037f63a5a1572702dd469f62f31f469',
127
+ '0x84c1da28b2f29f0a2b0ff360d537d405d1cd69249fcf5f32ae9c2298cee6da12',
128
+ '0xe8655dc68f2b765c5e6d4a042ba7ba8606cf37e1c8c96676f85364ec5bfe9163',
129
+ '0xf5c140bcb4814dfec311d38f6293e86c02d32ba1b7da027fe5b5202cae35dbc6',
130
+ ]);
131
+
132
+ expect(beaconSetId).toBe('0x33bf380fd5b06a317a905b23eaf5c61ef0a9b4a20589a1bf1d13133daca34b0e');
133
+ });
134
+
135
+ it('encodes a string as a bytes32 string', () => {
136
+ const formattedString = toBytes32String('test string');
137
+
138
+ expect(formattedString).toBe('0x7465737420737472696e67000000000000000000000000000000000000000000');
139
+ });
140
+
141
+ it('decodes a bytes32 string to a normal string', () => {
142
+ const formattedString = fromBytes32String('0x7465737420737472696e67000000000000000000000000000000000000000000');
143
+
144
+ expect(formattedString).toBe('test string');
145
+ });
146
+ });
147
+ });
@@ -0,0 +1,116 @@
1
+ import { ethers } from 'ethers';
2
+
3
+ import { addressSchema } from './schema';
4
+
5
+ export const PROTOCOL_IDS = {
6
+ RRP: '1',
7
+ PSP: '2',
8
+ RELAYED_RRP: '3',
9
+ RELAYED_PSP: '4',
10
+ AIRSEEKER: '5',
11
+ };
12
+
13
+ /**
14
+ * An interface that reflects the structure of a Template
15
+ */
16
+ export interface Template {
17
+ airnode: string;
18
+ encodedParameters: string;
19
+ endpointId: string;
20
+ }
21
+
22
+ /**
23
+ * Derives a template ID from the input parameters
24
+ *
25
+ * @param airnode an Airnode address
26
+ * @param encodedParameters encoded parameters, see the airnode/abi package's encode function
27
+ * @param endpointId An endpointID (see deriveEndpointId)
28
+ */
29
+ export const deriveTemplateId = ({ airnode, encodedParameters, endpointId }: Template) =>
30
+ ethers.utils.solidityKeccak256(['address', 'bytes32', 'bytes'], [airnode, endpointId, encodedParameters]);
31
+
32
+ /**
33
+ * Derives an endpoint ID
34
+ *
35
+ * @param oisTitle the OIS title
36
+ * @param endpointName the endpoint name
37
+ */
38
+ export const deriveEndpointId = (oisTitle: string, endpointName: string) =>
39
+ ethers.utils.keccak256(ethers.utils.defaultAbiCoder.encode(['string', 'string'], [oisTitle, endpointName]));
40
+
41
+ /**
42
+ * Derives an airnode address's xpub, required for allowing signed data consumers to verify authenticity
43
+ *
44
+ * @param airnodeMnemonic the airnode's mnemonic
45
+ */
46
+ export const deriveAirnodeXpub = (airnodeMnemonic: string) =>
47
+ ethers.utils.HDNode.fromMnemonic(airnodeMnemonic).derivePath("m/44'/60'/0'").neuter().extendedKey;
48
+
49
+ /**
50
+ * Derives a wallet path from a sponsor address, used for calculating a sponsor wallet.
51
+ *
52
+ * @param sponsorAddress an EVM-compatible address
53
+ * @param protocolId an API application protocol ID
54
+ */
55
+ export function deriveWalletPathFromSponsorAddress(sponsorAddress: string, protocolId: string) {
56
+ addressSchema.parse(sponsorAddress);
57
+
58
+ const sponsorAddressBN = ethers.BigNumber.from(sponsorAddress);
59
+ const paths = [];
60
+ for (let i = 0; i < 6; i++) {
61
+ const shiftedSponsorAddressBN = sponsorAddressBN.shr(31 * i);
62
+ paths.push(shiftedSponsorAddressBN.mask(31).toString());
63
+ }
64
+ return `${protocolId}/${paths.join('/')}`;
65
+ }
66
+
67
+ /**
68
+ * Encodes/formats a string as a hex-encoded bytes32 string.
69
+ *
70
+ * @param input the input string
71
+ */
72
+ export const toBytes32String = (input: string) => ethers.utils.formatBytes32String(input);
73
+
74
+ /**
75
+ * Decodes a hex-encoded bytes32 string to a normal string.
76
+ *
77
+ * @param input the input hex string
78
+ */
79
+ export const fromBytes32String = (input: string) => ethers.utils.parseBytes32String(input);
80
+
81
+ /**
82
+ * Derives a sponsor wallet, given a mnemonic and dapiName.
83
+ *
84
+ * @param sponsorWalletMnemonic the sponsor wallet mnemonic
85
+ * @param dapiName the dapi name
86
+ */
87
+ export const deriveSponsorWallet = (sponsorWalletMnemonic: string, dapiName: string) => {
88
+ // Take first 20 bytes of dapiName as sponsor address together with the "0x" prefix.
89
+ const sponsorAddress = ethers.utils.getAddress(dapiName.slice(0, 42));
90
+ const sponsorWallet = ethers.Wallet.fromMnemonic(
91
+ sponsorWalletMnemonic,
92
+ `m/44'/60'/0'/${
93
+ (deriveWalletPathFromSponsorAddress(sponsorAddress, PROTOCOL_IDS.AIRSEEKER), PROTOCOL_IDS.AIRSEEKER)
94
+ }`
95
+ );
96
+
97
+ return sponsorWallet;
98
+ };
99
+
100
+ /**
101
+ * Derives the ID of a single beacon
102
+ *
103
+ * @param airnodeAddress the airnode address of the provider that supplies the data used to update this beacon
104
+ * @param templateId the templateId of the template used to generate the data used to update this beacon
105
+ */
106
+ export const deriveBeaconId = (airnodeAddress: string, templateId: string) =>
107
+ ethers.utils.solidityKeccak256(['address', 'bytes32'], [airnodeAddress, templateId]);
108
+
109
+ /**
110
+ * Derives the ID of a set of beacons.
111
+ * By convention beacon IDs are sorted alphabetically - the ordering impacts the resulting hash.
112
+ *
113
+ * @param beaconIds an ordered array of beacon ids
114
+ */
115
+ export const deriveBeaconSetId = (beaconIds: string[]) =>
116
+ ethers.utils.keccak256(ethers.utils.defaultAbiCoder.encode(['bytes32[]'], [beaconIds]));
@@ -0,0 +1,23 @@
1
+ import { addressSchema, idSchema } from './schema';
2
+
3
+ describe('schema', () => {
4
+ it('validates a valid address', () => {
5
+ expect(() => addressSchema.parse('0x8A45eac0267dD0803Fd957723EdE10693A076698')).not.toThrow();
6
+ });
7
+
8
+ it('throws for an invalid address', () => {
9
+ expect(() => addressSchema.parse('0xA8A45eac0267dD0803Fd957723EdE10693A076698')).toThrow(
10
+ expect.objectContaining({ name: 'ZodError' })
11
+ );
12
+ });
13
+
14
+ it('validates a valid ID', () => {
15
+ expect(() => idSchema.parse('0x3528e42b017a5fbf9d2993a2df04efc3ed474357575065a111b054ddf9de2acc')).not.toThrow();
16
+ });
17
+
18
+ it('throws for an invalid ID', () => {
19
+ expect(() => idSchema.parse('0xA3528e42b017a5fbf9d2993a2df04efc3ed474357575065a111b054ddf9de2acc')).toThrow(
20
+ expect.objectContaining({ name: 'ZodError' })
21
+ );
22
+ });
23
+ });
@@ -0,0 +1,14 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * A Zod validation schema that represents an EVM-compatible address.
5
+ */
6
+ export const addressSchema = z.string().regex(/^0x[\dA-Fa-f]{40}$/, 'Must be a valid EVM address');
7
+
8
+ /**
9
+ * A Zod validation schema that represents an EVM-compatible hash, which includes beacon IDs and template IDs.
10
+ */
11
+ export const idSchema = z.string().regex(/^0x[\dA-Fa-f]{64}$/, 'Must be a valid EVM hash');
12
+
13
+ export type Address = z.infer<typeof addressSchema>;
14
+ export type Id = z.infer<typeof idSchema>;
@@ -6,40 +6,115 @@ The pre/post processing is only supported for Node.js environments and uses inte
6
6
 
7
7
  ## Documentation
8
8
 
9
- The processing module exports two main functions:
9
+ The processing module exports a multiple functions related to processing (both version 1 and 2). The most important
10
+ functions are:
10
11
 
11
12
  <!-- NOTE: These are copied over from "processing.d.ts" from "dist" file. -->
12
13
 
13
14
  ```ts
14
15
  /**
15
- * Pre-processes API call parameters based on the provided endpoint's processing specifications.
16
+ * Pre-processes endpoint parameters based on the provided endpoint's processing specifications.
17
+ *
18
+ * @param preProcessingSpecifications The v1 pre-processing specifications.
19
+ * @param endpointParameters The parameters to be pre-processed.
20
+ * @param processingOptions Options to control the async processing behavior like retries and timeouts.
21
+ *
22
+ * @returns A promise that resolves to the pre-processed parameters.
23
+ */
24
+ export declare const preProcessEndpointParametersV1: (
25
+ preProcessingSpecifications: ProcessingSpecifications | undefined,
26
+ endpointParameters: EndpointParameters,
27
+ processingOptions?: GoAsyncOptions
28
+ ) => Promise<EndpointParameters>;
29
+
30
+ /**
31
+ * Post-processes the response based on the provided endpoint's processing specifications. The response is usually the
32
+ * API call response, but this logic depends on how the processing is used by the target service. For example, Airnode
33
+ * allows skipping API calls in which case the response is the result of pre-processing.
34
+ *
35
+ * @param response The response to be post-processed.
36
+ * @param postProcessingSpecifications The v1 post-processing specifications.
37
+ * @param endpointParameters The endpoint parameters.
38
+ * @param processingOptions Options to control the async processing behavior like retries and timeouts.
39
+ *
40
+ * @returns A promise that resolves to the post-processed response.
41
+ */
42
+ export declare const postProcessResponseV1: (
43
+ response: unknown,
44
+ postProcessingSpecifications: ProcessingSpecifications | undefined,
45
+ endpointParameters: EndpointParameters,
46
+ processingOptions?: GoAsyncOptions
47
+ ) => Promise<unknown>;
48
+
49
+ /**
50
+ * Pre-processes endpoint parameters based on the provided endpoint's processing specifications.
51
+ *
52
+ * @param preProcessingSpecificationV2 The v2 pre-processing specification.
53
+ * @param endpointParameters The parameters to be pre-processed.
54
+ * @param processingOptions Options to control the async processing behavior like retries and timeouts.
55
+ *
56
+ * @returns A promise that resolves to the pre-processed parameters.
57
+ */
58
+ export declare const preProcessEndpointParametersV2: (
59
+ preProcessingSpecificationV2: ProcessingSpecificationV2 | undefined,
60
+ endpointParameters: EndpointParameters,
61
+ processingOptions?: GoAsyncOptions
62
+ ) => Promise<PreProcessingV2Response>;
63
+
64
+ /**
65
+ * Post-processes the response based on the provided endpoint's processing specifications. The response is usually the
66
+ * API call response, but this logic depends on how the processing is used by the target service. For example, Airnode
67
+ * allows skipping API calls in which case the response is the result of pre-processing.
68
+ *
69
+ * @param response The response to be post-processed.
70
+ * @param postProcessingSpecificationV2 The v2 post-processing specification.
71
+ * @param endpointParameters The endpoint parameters.
72
+ * @param processingOptions Options to control the async processing behavior like retries and timeouts.
73
+ *
74
+ * @returns A promise that resolves to the post-processed response.
75
+ */
76
+ export declare const postProcessResponseV2: (
77
+ response: unknown,
78
+ postProcessingSpecificationV2: ProcessingSpecificationV2 | undefined,
79
+ endpointParameters: EndpointParameters,
80
+ processingOptions?: GoAsyncOptions
81
+ ) => Promise<PostProcessingV2Response>;
82
+
83
+ /**
84
+ * Pre-processes endpoint parameters based on the provided endpoint's processing specifications. Internally it
85
+ * determines what processing implementation should be used.
16
86
  *
17
87
  * @param endpoint The endpoint containing processing specifications.
18
- * @param apiCallParameters The parameters to be pre-processed.
88
+ * @param endpointParameters The parameters to be pre-processed.
19
89
  * @param processingOptions Options to control the async processing behavior like retries and timeouts.
20
90
  *
21
91
  * @returns A promise that resolves to the pre-processed parameters.
22
92
  */
23
- export declare const preProcessApiCallParameters: (
93
+ export declare const preProcessEndpointParameters: (
24
94
  endpoint: Endpoint,
25
- apiCallParameters: ApiCallParameters,
95
+ endpointParameters: EndpointParameters,
26
96
  processingOptions?: GoAsyncOptions
27
- ) => Promise<ApiCallParameters>;
97
+ ) => Promise<PreProcessingV2Response>;
28
98
 
29
99
  /**
30
- * Post-processes the API call response based on the provided endpoint's processing specifications.
100
+ * Post-processes the response based on the provided endpoint's processing specifications. The response is usually the
101
+ * API call response, but this logic depends on how the processing is used by the target service. For example, Airnode
102
+ * allows skipping API calls in which case the response is the result of pre-processing.
31
103
  *
32
- * @param apiCallResponse The raw response obtained from the API call.
104
+ * This function determines what processing version should be used and provides a common interface. This is useful for
105
+ * services that want to use processing and don't care which processing version is used.
106
+ *
107
+ * @param response The response to be post-processed.
33
108
  * @param endpoint The endpoint containing processing specifications.
34
- * @param apiCallParameters The parameters used in the API call.
109
+ * @param endpointParameters The endpoint parameters.
35
110
  * @param processingOptions Options to control the async processing behavior like retries and timeouts.
36
111
  *
37
- * @returns A promise that resolves to the post-processed API call response.
112
+ * @returns A promise that resolves to the post-processed response.
38
113
  */
39
- export declare const postProcessApiCallResponse: (
40
- apiCallResponse: unknown,
114
+ export declare const postProcessResponse: (
115
+ response: unknown,
41
116
  endpoint: Endpoint,
42
- apiCallParameters: ApiCallParameters,
117
+ endpointParameters: EndpointParameters,
43
118
  processingOptions?: GoAsyncOptions
44
- ) => Promise<unknown>;
119
+ ) => Promise<PostProcessingV2Response>;
45
120
  ```