From 0954c9c9aa2d93de99fc74ec735c67a52759ad66 Mon Sep 17 00:00:00 2001 From: gabaldon Date: Tue, 13 Aug 2024 11:17:37 +0200 Subject: [PATCH] fix: change cbor library --- package-lock.json | 39 ++++++++++----------------------------- package.json | 2 +- src/bin/toolkit.js | 6 +++--- src/index.js | 8 ++++---- src/lib/rad2sol/index.js | 4 ++-- src/lib/radon/index.js | 4 ++-- src/lib/radon/request.js | 4 +++- src/lib/radon/script.js | 6 +++--- src/lib/radon/stages.js | 10 +++++----- src/lib/radon/types.js | 2 +- 10 files changed, 34 insertions(+), 51 deletions(-) diff --git a/package-lock.json b/package-lock.json index eaff3a7..b398a28 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.9.12", "license": "MIT", "dependencies": { - "cbor": "^9.0.1", + "cbor2": "^1.4.0", "core-js": "^3.35.1", "glob": "^10.3.10", "graphql-query-compress": "^1.2.4", @@ -979,15 +979,12 @@ "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==" }, - "node_modules/cbor": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/cbor/-/cbor-9.0.1.tgz", - "integrity": "sha512-/TQOWyamDxvVIv+DY9cOLNuABkoyz8K/F3QE56539pGVYohx0+MEA1f4lChFTX79dBTBS7R1PF6ovH7G+VtBfQ==", - "dependencies": { - "nofilter": "^3.1.0" - }, + "node_modules/cbor2": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/cbor2/-/cbor2-1.7.0.tgz", + "integrity": "sha512-/xTBkiy6NGfW3NVMHMJpIKGwMgxtwfzmLGh81PpvGeBKP2Tjkg9i8IAly1bImbFsNbGevs8MFP8Oadsq7DMSLg==", "engines": { - "node": ">=16" + "node": ">=18" } }, "node_modules/chai": { @@ -1750,14 +1747,6 @@ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" } }, - "node_modules/nofilter": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/nofilter/-/nofilter-3.1.0.tgz", - "integrity": "sha512-l2NNj07e9afPnhAhvgVrCD/oy2Ai1yfLpuo3EpiO1jFTsB4sFz6oIfAfSZyQzVpkZQ9xS8ZS5g1jCBgq4Hwo0g==", - "engines": { - "node": ">=12.19" - } - }, "node_modules/oauth-sign": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", @@ -3326,13 +3315,10 @@ "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==" }, - "cbor": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/cbor/-/cbor-9.0.1.tgz", - "integrity": "sha512-/TQOWyamDxvVIv+DY9cOLNuABkoyz8K/F3QE56539pGVYohx0+MEA1f4lChFTX79dBTBS7R1PF6ovH7G+VtBfQ==", - "requires": { - "nofilter": "^3.1.0" - } + "cbor2": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/cbor2/-/cbor2-1.7.0.tgz", + "integrity": "sha512-/xTBkiy6NGfW3NVMHMJpIKGwMgxtwfzmLGh81PpvGeBKP2Tjkg9i8IAly1bImbFsNbGevs8MFP8Oadsq7DMSLg==" }, "chai": { "version": "4.4.1", @@ -3918,11 +3904,6 @@ "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==", "dev": true }, - "nofilter": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/nofilter/-/nofilter-3.1.0.tgz", - "integrity": "sha512-l2NNj07e9afPnhAhvgVrCD/oy2Ai1yfLpuo3EpiO1jFTsB4sFz6oIfAfSZyQzVpkZQ9xS8ZS5g1jCBgq4Hwo0g==" - }, "oauth-sign": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", diff --git a/package.json b/package.json index 8ac02ec..85b4810 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "witnet-solidity-bridge": "^0.5.1" }, "dependencies": { - "cbor": "^9.0.1", + "cbor2": "^1.4.0", "core-js": "^3.35.1", "glob": "^10.3.10", "graphql-query-compress": "^1.2.4", diff --git a/src/bin/toolkit.js b/src/bin/toolkit.js index 2f308bc..664e911 100755 --- a/src/bin/toolkit.js +++ b/src/bin/toolkit.js @@ -6,7 +6,7 @@ import {loadSchema} from "../lib/rad2sol/steps.js"; import {readCompileEncodeScript} from "../lib/rad2sol/scripts.js"; -import cbor from 'cbor' +import { decode } from 'cbor2'; import fs from 'node:fs' import os from 'node:os' import path from 'node:path' @@ -225,7 +225,7 @@ async function forcedInstallCommand (settings) { function decodeFilters (mir) { return mir.map((filter) => { if (filter.args.length > 0) { - const decodedArgs = cbor.decode(Buffer.from(filter.args)) + const decodedArgs = decode(Buffer.from(filter.args)) return {...filter, args: decodedArgs} } else { return filter @@ -236,7 +236,7 @@ function decodeFilters (mir) { function decodeScriptsAndArguments (mir) { let decoded = mir.data_request decoded.retrieve = decoded.retrieve.map((source) => { - const decodedScript = cbor.decode(Buffer.from(source.script)) + const decodedScript = decode(Buffer.from(source.script)) return {...source, script: decodedScript} }) decoded.aggregate.filters = decodeFilters(decoded.aggregate.filters) diff --git a/src/index.js b/src/index.js index 46388f8..7753dd4 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ -import { Script } from "./lib/radon/script" -import { Aggregator, GraphQLSource, HttpGetSource, HttpPostSource, RandomSource, Tally } from "./lib/radon/stages" -import { Request } from "./lib/radon/request" -import * as Types from "./lib/radon/types" +import { Script } from "./lib/radon/script.js" +import { Aggregator, GraphQLSource, HttpGetSource, HttpPostSource, RandomSource, Tally } from "./lib/radon/stages.js" +import { Request } from "./lib/radon/request.js" +import * as Types from "./lib/radon/types.js" const TYPES = Types.TYPES; diff --git a/src/lib/rad2sol/index.js b/src/lib/rad2sol/index.js index 35008da..f04029d 100644 --- a/src/lib/rad2sol/index.js +++ b/src/lib/rad2sol/index.js @@ -1,5 +1,5 @@ -import * as Scripts from "./scripts" -import * as Steps from "./steps" +import * as Scripts from "./scripts.js" +import * as Steps from "./steps.js" export { Scripts, diff --git a/src/lib/radon/index.js b/src/lib/radon/index.js index fe41df2..0ae2728 100644 --- a/src/lib/radon/index.js +++ b/src/lib/radon/index.js @@ -1,5 +1,5 @@ -import { Request } from './request'; -import TYPES from './types'; +import { Request } from './request.js'; +import TYPES from './types.js'; export default { diff --git a/src/lib/radon/request.js b/src/lib/radon/request.js index 0d96dc7..8f1dadc 100644 --- a/src/lib/radon/request.js +++ b/src/lib/radon/request.js @@ -1,4 +1,4 @@ -import {FILTERS, REDUCERS} from "./types"; +import {FILTERS, REDUCERS} from "./types.js"; class Request { constructor () { @@ -7,6 +7,8 @@ class Request { retrieve: [], aggregate: null, tally: null, + // This field is deprecated, it will default to 0 to be succesfully encoded + time_lock: 0, }, value: 0, witnesses: 2, diff --git a/src/lib/radon/script.js b/src/lib/radon/script.js index 8d1fbca..091d9c7 100644 --- a/src/lib/radon/script.js +++ b/src/lib/radon/script.js @@ -1,5 +1,5 @@ -import * as CBOR from "cbor"; -import {PSEUDOTYPES, typeFormat, TYPES, typeSystem} from "./types"; +import { encode } from 'cbor2'; +import {PSEUDOTYPES, typeFormat, TYPES, typeSystem} from "./types.js"; function unpackArgs(args) { return args.map((arg) => { @@ -72,7 +72,7 @@ class Script { } encode () { - return CBOR.encode(this.script) + return encode(this.script) } } diff --git a/src/lib/radon/stages.js b/src/lib/radon/stages.js index e390cca..0546c9e 100644 --- a/src/lib/radon/stages.js +++ b/src/lib/radon/stages.js @@ -1,7 +1,7 @@ -import * as CBOR from "cbor"; -import { Script } from "./script"; -import { FILTERS, REDUCERS, RETRIEVAL_METHODS, TYPES } from "./types"; -import { graphQlSanitize } from "../../utils"; +import { encode } from 'cbor2'; +import { Script } from "./script.js"; +import { FILTERS, REDUCERS, RETRIEVAL_METHODS, TYPES } from "./types.js"; +import { graphQlSanitize } from "../../utils.js"; class Source extends Script { constructor(kind, firstType) { @@ -51,7 +51,7 @@ class Joiner { filters: this.filters.map(([op, ...raw_args]) => { let raw_args_len = raw_args.length; let args = raw_args_len > 0 ? raw_args_len > 1 ? raw_args : raw_args[0] : []; - return { op, args: CBOR.encode(args) } + return { op, args: encode(args) } }), reducer: this.reducer, } diff --git a/src/lib/radon/types.js b/src/lib/radon/types.js index 93780cd..a3203b8 100644 --- a/src/lib/radon/types.js +++ b/src/lib/radon/types.js @@ -152,7 +152,7 @@ const typeSystem = { const RETRIEVAL_METHODS = { HttpGet: 0x01, Rng: 0x02, - HttpPost: 0x03, + HttpPost: 0x03 } // Helper function that helps pretty-printing RADON types