From 2c6d90acd237167f6732d2f8d85e07c11d4d48a4 Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Tue, 31 Oct 2023 10:09:26 +0100 Subject: [PATCH 01/10] add new gas parameter + remove unused gasPrice --- src/constants/constants.ts | 14 ++------------ src/index.ts | 23 +++++++++++++++------- src/lib/provider-wrapper-utils.ts | 7 +++++-- src/provider/providerWrapper.ts | 32 +++++++++++++++++++++++++------ src/types/Config.ts | 1 + src/types/Method.ts | 2 -- 6 files changed, 50 insertions(+), 29 deletions(-) diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 4915183d..21eb28f5 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -58,47 +58,35 @@ export const METHODS: Record = { [Method.GET_DATA_LEGACY]: { // Legacy version of ERC725Y - before v0.3.0 sig: '0x54f6127f', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BYTES, }, [Method.GET_DATA]: { // https://github.com/ERC725Alliance/ERC725/blob/v4.0.0/docs/ERC-725.md#erc725y sig: '0x4e3e6e9c', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BYTES_ARRAY, }, [Method.GET_DATA_BATCH]: { // https://github.com/ERC725Alliance/ERC725/blob/v5.1.0/docs/ERC-725.md#erc725y sig: '0xdedff9c6', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BYTES_ARRAY, }, [Method.OWNER]: { sig: '0x8da5cb5b', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.ADDRESS, }, [Method.SUPPORTS_INTERFACE]: { // https://eips.ethereum.org/EIPS/eip-165 sig: '0x01ffc9a7', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BOOL, }, [Method.IS_VALID_SIGNATURE]: { // https://eips.ethereum.org/EIPS/eip-1271 sig: '0x1626ba7e', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BYTES4, }, @@ -183,3 +171,5 @@ export const LSP6_ALL_PERMISSIONS = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'; export const COMPACT_BYTES_ARRAY_STRING = '[CompactBytesArray]'; + +export const DEFAULT_GAS_VALUE = 2000000; diff --git a/src/index.ts b/src/index.ts index 6a07e404..ec12ebbe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,6 +37,7 @@ import { isValidSignature } from './lib/isValidSignature'; import { LSP6_ALL_PERMISSIONS, LSP6_DEFAULT_PERMISSIONS, + DEFAULT_GAS_VALUE, } from './constants/constants'; import { encodeKeyName, isDynamicKeyName } from './lib/encodeKeyName'; @@ -105,15 +106,20 @@ export class ERC725 { const defaultConfig = { ipfsGateway: 'https://cloudflare-ipfs.com/ipfs/', + gas: DEFAULT_GAS_VALUE, }; this.options = { schemas: this.validateSchemas(schemas), address, - provider: ERC725.initializeProvider(provider), + provider: ERC725.initializeProvider( + provider, + config?.gas ? config?.gas : defaultConfig.gas, + ), ipfsGateway: config?.ipfsGateway ? convertIPFSGatewayUrl(config?.ipfsGateway) : defaultConfig.ipfsGateway, + gas: config?.gas ? config?.gas : defaultConfig.gas, }; } @@ -151,20 +157,20 @@ export class ERC725 { }); } - private static initializeProvider(providerOrRpcUrl) { + private static initializeProvider(providerOrRpcUrl, gasInfo) { // do not fail on no-provider if (!providerOrRpcUrl) return undefined; // if provider is a string, assume it's a rpcUrl if (typeof providerOrRpcUrl === 'string') { - return new ProviderWrapper(new HttpProvider(providerOrRpcUrl)); + return new ProviderWrapper(new HttpProvider(providerOrRpcUrl), gasInfo); } if ( typeof providerOrRpcUrl.request === 'function' || typeof providerOrRpcUrl.send === 'function' ) - return new ProviderWrapper(providerOrRpcUrl); + return new ProviderWrapper(providerOrRpcUrl, gasInfo); throw new Error(`Incorrect or unsupported provider ${providerOrRpcUrl}`); } @@ -593,12 +599,12 @@ export class ERC725 { * supports a certain interface. * * @param {string} interfaceIdOrName Interface ID or supported interface name. - * @param options Object of address and RPC URL. + * @param options Object of address, RPC URL and optional gas. * @returns {Promise} if interface is supported. */ static async supportsInterface( interfaceIdOrName: string, - options: { address: string; rpcUrl: string }, + options: { address: string; rpcUrl: string; gas?: number }, ): Promise { if (!isAddress(options.address)) { throw new Error('Invalid address'); @@ -609,7 +615,10 @@ export class ERC725 { return supportsInterface(interfaceIdOrName, { address: options.address, - provider: this.initializeProvider(options.rpcUrl), + provider: this.initializeProvider( + options.rpcUrl, + options?.gas ? options?.gas : DEFAULT_GAS_VALUE, + ), }); } diff --git a/src/lib/provider-wrapper-utils.ts b/src/lib/provider-wrapper-utils.ts index 5f2adf67..0a0d52a0 100644 --- a/src/lib/provider-wrapper-utils.ts +++ b/src/lib/provider-wrapper-utils.ts @@ -13,6 +13,7 @@ */ import * as abi from 'web3-eth-abi'; +import { numberToHex } from 'web3-utils'; import { JsonRpc, @@ -49,6 +50,7 @@ export function decodeResult(method: Method, hexString: string) { const constructJSONRPCParams = ( address: string, method: Method, + gasInfo: number, methodParam?: string, ): JsonRpcEthereumProviderParamsWithLatest => { const data = methodParam @@ -59,7 +61,7 @@ const constructJSONRPCParams = ( { to: address, value: METHODS[method].value, - gas: METHODS[method].gas, + gas: numberToHex(gasInfo), data, }, 'latest', @@ -69,13 +71,14 @@ const constructJSONRPCParams = ( export function constructJSONRPC( address: string, method: Method, + gasInfo: number, methodParam?: string, ): JsonRpc { idCount += 1; return { jsonrpc: '2.0', method: 'eth_call', - params: constructJSONRPCParams(address, method, methodParam), + params: constructJSONRPCParams(address, method, gasInfo, methodParam), id: idCount, }; } diff --git a/src/provider/providerWrapper.ts b/src/provider/providerWrapper.ts index 3f7026db..a3f235d1 100644 --- a/src/provider/providerWrapper.ts +++ b/src/provider/providerWrapper.ts @@ -40,18 +40,20 @@ interface GetDataReturn { export class ProviderWrapper { type: ProviderTypes; provider: any; - constructor(provider: any) { + gas: number; + constructor(provider: any, gasInfo: number) { if (typeof provider.request === 'function') { this.type = ProviderTypes.ETHEREUM; } else { this.type = ProviderTypes.WEB3; } this.provider = provider; + this.gas = gasInfo; } async getOwner(address: string) { const result = await this.callContract( - constructJSONRPC(address, Method.OWNER), + constructJSONRPC(address, Method.OWNER, this.gas), ); if (result.error) { throw result.error; @@ -115,6 +117,7 @@ export class ProviderWrapper { constructJSONRPC( address, Method.SUPPORTS_INTERFACE, + this.gas, `${interfaceId}${'00000000000000000000000000000000000000000000000000000000'}`, ), ); @@ -152,7 +155,12 @@ export class ProviderWrapper { ); const result = await this.callContract( - constructJSONRPC(address, Method.IS_VALID_SIGNATURE, encodedParams), + constructJSONRPC( + address, + Method.IS_VALID_SIGNATURE, + this.gas, + encodedParams, + ), ); if (result.error) { @@ -172,7 +180,12 @@ export class ProviderWrapper { ); const results = await this.callContract([ - constructJSONRPC(address, Method.IS_VALID_SIGNATURE, encodedParams), + constructJSONRPC( + address, + Method.IS_VALID_SIGNATURE, + this.gas, + encodedParams, + ), ]); if (results.error) { throw results.error; @@ -232,6 +245,7 @@ export class ProviderWrapper { constructJSONRPC( address, method, + this.gas, abiCoder.encodeParameter('bytes32[]', keyHashes), ), ); @@ -248,6 +262,7 @@ export class ProviderWrapper { constructJSONRPC( address, method, + this.gas, abiCoder.encodeParameter('bytes32[]', keyHashes), ), ]; @@ -270,7 +285,7 @@ export class ProviderWrapper { // But this is already legacy and it won't be used anymore.. const encodedResultsPromises = keyHashes.map((keyHash) => this.callContract( - constructJSONRPC(address, Method.GET_DATA_LEGACY, keyHash), + constructJSONRPC(address, Method.GET_DATA_LEGACY, this.gas, keyHash), ), ); @@ -287,7 +302,12 @@ export class ProviderWrapper { // But this is already legacy and it won't be used anymore.. for (let index = 0; index < keyHashes.length; index++) { payload.push( - constructJSONRPC(address, Method.GET_DATA_LEGACY, keyHashes[index]), + constructJSONRPC( + address, + Method.GET_DATA_LEGACY, + this.gas, + keyHashes[index], + ), ); } diff --git a/src/types/Config.ts b/src/types/Config.ts index 24e4ab33..fa40adbb 100644 --- a/src/types/Config.ts +++ b/src/types/Config.ts @@ -11,6 +11,7 @@ export interface ERC725Config { * Another example: `https://cloudflare-ipfs.com/ipfs/` */ ipfsGateway: string; + gas: number; } export interface ERC725Options { diff --git a/src/types/Method.ts b/src/types/Method.ts index e28b49ab..1c794a67 100644 --- a/src/types/Method.ts +++ b/src/types/Method.ts @@ -19,8 +19,6 @@ export enum Encoding { export interface MethodData { sig: string; - gas: string; - gasPrice: string; value: string; returnEncoding: Encoding; } From 14e600c74c2d8a3551b0e984a807a65ce5157c36 Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Tue, 31 Oct 2023 10:27:54 +0100 Subject: [PATCH 02/10] fixing test + no magic number --- src/constants/constants.ts | 2 +- src/provider/providerWrapper.test.ts | 7 ++++--- src/types/Config.ts | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 21eb28f5..c9948fc9 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -172,4 +172,4 @@ export const LSP6_ALL_PERMISSIONS = export const COMPACT_BYTES_ARRAY_STRING = '[CompactBytesArray]'; -export const DEFAULT_GAS_VALUE = 2000000; +export const DEFAULT_GAS_VALUE = 2_000_000; diff --git a/src/provider/providerWrapper.test.ts b/src/provider/providerWrapper.test.ts index 91748eb3..75e8ed94 100644 --- a/src/provider/providerWrapper.test.ts +++ b/src/provider/providerWrapper.test.ts @@ -3,6 +3,7 @@ import assert from 'assert'; import { ProviderWrapper } from './providerWrapper'; const erc725AccountAddress = '0x214be121bB52e6909c5158579b3458f8760f1b2f'; +const defaultGas = 2_000_000; describe('ProviderWrapper', () => { describe('#getOwner', () => { @@ -15,7 +16,7 @@ describe('ProviderWrapper', () => { }); }, }; - const ethSource = new ProviderWrapper(mockProvider); + const ethSource = new ProviderWrapper(mockProvider, defaultGas); const owner = await ethSource.getOwner(erc725AccountAddress); assert.deepStrictEqual( @@ -30,7 +31,7 @@ describe('ProviderWrapper', () => { cb(new Error('some error')); }, }; - const ethSource = new ProviderWrapper(mockProvider); + const ethSource = new ProviderWrapper(mockProvider, defaultGas); try { await ethSource.getOwner(erc725AccountAddress); @@ -47,7 +48,7 @@ describe('ProviderWrapper', () => { }); }, }; - const ethSource = new ProviderWrapper(mockProvider); + const ethSource = new ProviderWrapper(mockProvider, defaultGas); try { await ethSource.getOwner(erc725AccountAddress); diff --git a/src/types/Config.ts b/src/types/Config.ts index fa40adbb..15707591 100644 --- a/src/types/Config.ts +++ b/src/types/Config.ts @@ -5,13 +5,14 @@ export interface ERC725Config { * ```js title=Example * const config = { * ipfsGateway: 'https://ipfs.lukso.network/ipfs/' + * gas: 20_000_000 // Optional, default 2_000_000 * }; * ``` * Make sure to use the following format: `/ipfs/`.
* Another example: `https://cloudflare-ipfs.com/ipfs/` */ ipfsGateway: string; - gas: number; + gas?: number; } export interface ERC725Options { From 0d0f725cfafea1650f82cf353a0f307123a77548 Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Tue, 31 Oct 2023 10:37:29 +0100 Subject: [PATCH 03/10] update docs --- docs/classes/ERC725.md | 2 ++ docs/getting-started.md | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/classes/ERC725.md b/docs/classes/ERC725.md index c6a41019..48985771 100644 --- a/docs/classes/ERC725.md +++ b/docs/classes/ERC725.md @@ -1446,6 +1446,7 @@ On non instantiated class, you should provide an `options` object. | :-------- | :----- | :------------------------------------------------------------------- | | `address` | string | Address of the smart contract to check against a certain interface. | | `rpcUrl` | string | RPC URL to connect to the network the smart contract is deployed to. | +| `gas` | number | Optional: gas parameter to use. Default: 2_000_000. | #### Returns @@ -1473,6 +1474,7 @@ myErc725.supportsInterface('LSP0ERC725Account'); ERC725.supportsInterface('LSP0ERC725Account', { address: '0x0Dc07C77985fE31996Ed612F568eb441afe5768D', rpcUrl: 'https://rpc.testnet.lukso.network', + gas: 20_000_000, }); // true ``` diff --git a/docs/getting-started.md b/docs/getting-started.md index cbe47702..71b05e92 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -61,6 +61,7 @@ const address = '0x0Dc07C77985fE31996Ed612F568eb441afe5768D'; const RPC_URL = 'https://rpc.testnet.lukso.network'; const config = { ipfsGateway: 'https://YOUR-IPFS-GATEWAY/ipfs/', + gas: 20_000_000, // optional, default is 2_000_000 }; const erc725 = new ERC725(schemas, address, RPC_URL, config); @@ -110,7 +111,7 @@ await erc725.fetchData('LSP3Profile'); // downloads and verifies the linked JSON ``` :::tip Try it out -You can run the code snippit within your browser using the corresponding [StackBlitz example](https://stackblitz.com/edit/erc725js-instantiation?devtoolsheight=66&file=index.js). +You can run the code snippet within your browser using the corresponding [StackBlitz example](https://stackblitz.com/edit/erc725js-instantiation?devtoolsheight=66&file=index.js). :::note Whenever you can you should import `ERC725` via the named export. However currently we are also providing a default export. @@ -127,6 +128,7 @@ After the instance has been created, it is still possible to change settings thr myERC725.options.schema = '' // change schema myERC725.options.address '
' // change address myERC725.options.ipfsGateway = '' // used for fetchData(), default: 'https://cloudflare-ipfs.com/ipfs/' +myERC725.options.gas = 20_000_000 // change gas setting // NOTE: ERC725.provider can not be changed ``` From a4671545f88be89d3733957a28cbbab99df3e211 Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Tue, 31 Oct 2023 16:03:18 +0100 Subject: [PATCH 04/10] renaming hashFunction --- README.md | 4 +-- docs/classes/ERC725.md | 46 ++++++++++++++------------- docs/getting-started.md | 2 +- examples/src/decodeData.js | 8 ++--- examples/src/encodeData.js | 10 +++--- examples/src/getData.js | 12 +++---- examples/src/instantiation.js | 37 ++++++++++++--------- src/constants/constants.ts | 35 ++++++++++---------- src/index.test.ts | 44 ++++++++++++++----------- src/lib/encoder.test.ts | 36 +++++++++++---------- src/lib/encoder.ts | 45 +++++++++++++++----------- src/lib/getDataFromExternalSources.ts | 12 +++---- src/lib/utils.test.ts | 35 ++++++++++++-------- src/lib/utils.ts | 30 +++++++++-------- src/types/encodeData/JSONURL.ts | 10 +++--- src/types/encodeData/index.ts | 6 ++-- test/mockSchema.ts | 25 +++++++++------ 17 files changed, 223 insertions(+), 174 deletions(-) diff --git a/README.md b/README.md index f3b7a5a3..d8f9131f 100644 --- a/README.md +++ b/README.md @@ -118,8 +118,8 @@ await myErc725.getData(); name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - hashFunction: 'keccak256(utf8)', - hash: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', + validationFunction: 'keccak256(utf8)', + validation: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', url: 'ipfs://QmecrGejUQVXpW4zS948pNvcnQrJ1KiAoM6bdfrVcWZsn5', }, }, diff --git a/docs/classes/ERC725.md b/docs/classes/ERC725.md index c6a41019..efb68640 100644 --- a/docs/classes/ERC725.md +++ b/docs/classes/ERC725.md @@ -147,8 +147,8 @@ myErc725.decodeData([ name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - hashFunction: 'keccak256(utf8)', - hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', + verificationFunction: 'keccak256(utf8)', + verificationData: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx', }, }, @@ -165,8 +165,8 @@ myErc725.decodeData({ name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - hashFunction: 'keccak256(utf8)', - hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', + verificationFunction: 'keccak256(utf8)', + verificationData: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx', }, } @@ -206,8 +206,8 @@ myErc725.decodeData([ name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', - hashFunction: 'keccak256(utf8)', + verificationData: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', + verificationFunction: 'keccak256(utf8)', url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx', }, }, @@ -256,8 +256,8 @@ myErc725.decodeData( name: 'MyKeyName:aaaabbbbccccddddeeeeffff111122223333444455556666777788889999aaaa:true', key: '0x35e6950bc8d2aaaabbbb00000000000000000000000000000000000000000001', value: { - hashFunction: 'keccak256(utf8)', - hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', + verificationFunction: 'keccak256(utf8)', + verificationData: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', url: 'ifps://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx', }, }, @@ -479,8 +479,9 @@ myErc725.encodeData([ { keyName: 'LSP3Profile', value: { - hashFunction: 'keccak256(utf8)', - hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', + verificationFunction: 'keccak256(utf8)', + verificationData: + '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx', }, }, @@ -564,8 +565,9 @@ myErc725.encodeData([ { keyName: 'LSP3Profile', value: { - hashFunction: 'keccak256(utf8)', - hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', + verificationFunction: 'keccak256(utf8)', + verificationData: + '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx', }, }, @@ -1063,8 +1065,8 @@ await myErc725.getData(); name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - hashFunction: 'keccak256(utf8)', - hash: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', + verificationFunction: 'keccak256(utf8)', + verificationData: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', url: 'ipfs://QmecrGejUQVXpW4zS948pNvcnQrJ1KiAoM6bdfrVcWZsn5', }, }, @@ -1081,8 +1083,8 @@ await myErc725.getData('LSP3Profile'); name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - hashFunction: 'keccak256(utf8)', - hash: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a', + verificationFunction: 'keccak256(utf8)', + verificationData: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a', url: 'ipfs://QmbTmcbp8ZW23vkQrqkasMFqNg2z1iP4e3BCUMz9PKDsSV' }, } @@ -1095,8 +1097,8 @@ await myErc725.getData(['LSP3Profile']); name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - hashFunction: 'keccak256(utf8)', - hash: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a', + verificationFunction: 'keccak256(utf8)', + verificationData: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a', url: 'ipfs://QmbTmcbp8ZW23vkQrqkasMFqNg2z1iP4e3BCUMz9PKDsSV' }, } @@ -1123,8 +1125,8 @@ await myErc725.getData(['LSP3Profile', 'LSP1UniversalReceiverDelegate']); name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - hashFunction: 'keccak256(utf8)', - hash: '0xeeafeebeb416923dfb0dcf4c66b045c72742121ce2a06f93ae044ee0efb70777', + verificationFunction: 'keccak256(utf8)', + verificationData: '0xeeafeebeb416923dfb0dcf4c66b045c72742121ce2a06f93ae044ee0efb70777', url: 'ipfs://QmZnG5Z5B5Dq8iFFtsL5i7AnrgH16P4DJ8UhY7j8RzX51p' } }, @@ -1183,8 +1185,8 @@ await myErc725.getData([ name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - hashFunction: 'keccak256(utf8)', - hash: '0xeeafeebeb416923dfb0dcf4c66b045c72742121ce2a06f93ae044ee0efb70777', + verificationFunction: 'keccak256(utf8)', + verificationData: '0xeeafeebeb416923dfb0dcf4c66b045c72742121ce2a06f93ae044ee0efb70777', url: 'ipfs://QmZnG5Z5B5Dq8iFFtsL5i7AnrgH16P4DJ8UhY7j8RzX51p' } }, diff --git a/docs/getting-started.md b/docs/getting-started.md index cbe47702..b05207ee 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -85,7 +85,7 @@ await erc725.getData(['LSP3Profile', 'SupportedStandards:LSP3Profile']); LSP3Profile: { url: 'ipfs://QmXybv2LdJWscy1C6yRKUjvnaj6aqKktZX4g4xmz2nyYj2', hash: '0xb4f9d72e83bbe7e250ed9ec80332c493b7b3d73e0d72f7b2c7ab01c39216eb1a', - hashFunction: 'keccak256(utf8)' + verificationFunction: 'keccak256(utf8)' }, 'SupportedStandards:LSP3Profile': '0x5ef83ad9' } diff --git a/examples/src/decodeData.js b/examples/src/decodeData.js index 474c9d45..0bc5551d 100644 --- a/examples/src/decodeData.js +++ b/examples/src/decodeData.js @@ -17,8 +17,8 @@ const decodedDataOneKey = myERC725.decodeData([ name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - hashFunction: 'keccak256(utf8)', - hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', + validationFunction: 'keccak256(utf8)', + validation: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx' } } @@ -56,8 +56,8 @@ const decodedDataManyKeys = myERC725.decodeData([ name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - hashFunction: 'keccak256(utf8)', - hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', + verificationFunction: 'keccak256(utf8)', + verificationData: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx' } }, diff --git a/examples/src/encodeData.js b/examples/src/encodeData.js index 39e7e3e6..85dd69c8 100644 --- a/examples/src/encodeData.js +++ b/examples/src/encodeData.js @@ -25,8 +25,9 @@ const encodedDataOneKey = myERC725.encodeData({ const encodedDataOneKeyV2 = myERC725.encodeData({ keyName: 'LSP3Profile', value: { - hashFunction: 'keccak256(utf8)', - hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', + verificationFunction: 'keccak256(utf8)', + verificationData: + '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx', }, }); @@ -45,8 +46,9 @@ const encodedDataManyKeys = myERC725.encodeData([ { keyName: 'LSP3Profile', value: { - hashFunction: 'keccak256(utf8)', - hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', + verificationFunction: 'keccak256(utf8)', + verificationData: + '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx', }, }, diff --git a/examples/src/getData.js b/examples/src/getData.js index 447ab21b..e34ac0d3 100644 --- a/examples/src/getData.js +++ b/examples/src/getData.js @@ -11,8 +11,8 @@ const dataAllKeys = await myERC725.getData(); name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - hashFunction: 'keccak256(utf8)', - hash: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a', + verificationFunction: 'keccak256(utf8)', + verificationData: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a', url: 'ipfs://QmbTmcbp8ZW23vkQrqkasMFqNg2z1iP4e3BCUMz9PKDsSV' } }, @@ -46,8 +46,8 @@ const dataOneKey = await myERC725.getData('LSP3Profile'); key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', name: 'LSP3Profile', value: { - hashFunction: 'keccak256(utf8)', - hash: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a', + verificationFunction: 'keccak256(utf8)', + verificationData: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a', url: 'ipfs://QmbTmcbp8ZW23vkQrqkasMFqNg2z1iP4e3BCUMz9PKDsSV' } } @@ -63,8 +63,8 @@ const dataManyKeys = await myERC725.getData([ key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', name: 'LSP3Profile', value: { - hashFunction: 'keccak256(utf8)', - hash: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a', + verificationFunction: 'keccak256(utf8)', + verificationData: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a', url: 'ipfs://QmbTmcbp8ZW23vkQrqkasMFqNg2z1iP4e3BCUMz9PKDsSV' } }, diff --git a/examples/src/instantiation.js b/examples/src/instantiation.js index cdaab9b2..54915414 100644 --- a/examples/src/instantiation.js +++ b/examples/src/instantiation.js @@ -61,36 +61,41 @@ export const profileJson = { { width: 1800, height: 1712, - hashFunction: 'keccak256(bytes)', - hash: '0xfbcfcbbc86d886e862419361c48251d778884a90429d36c8d002559cbcb52972', + verificationFunction: 'keccak256(bytes)', + verificationData: + '0xfbcfcbbc86d886e862419361c48251d778884a90429d36c8d002559cbcb52972', url: 'ipfs://QmNPh6hP5igFzPf4mPtKBa6Wttnmi3YNVMAptC7drzyeDB', }, { width: 1024, height: 974, - hashFunction: 'keccak256(bytes)', - hash: '0xa9399df007997de92a820c6c2ec1cb2d3f5aa5fc1adf294157de563eba39bb6e', + verificationFunction: 'keccak256(bytes)', + verificationData: + '0xa9399df007997de92a820c6c2ec1cb2d3f5aa5fc1adf294157de563eba39bb6e', url: 'ipfs://QmW4wM4r9yWeY1gUCtt7c6v3ve7Fzdg8CKvTS96NU9Uiwr', }, { width: 640, height: 609, - hashFunction: 'keccak256(bytes)', - hash: '0xb316a695125cb0566da252266cfc9d5750a740bbdffa86712bb17508e70e6a31', + verificationFunction: 'keccak256(bytes)', + verificationData: + '0xb316a695125cb0566da252266cfc9d5750a740bbdffa86712bb17508e70e6a31', url: 'ipfs://QmXGELsqGidAHMwYRsEv6Z4emzMggtc5GXZYGFK7r6zFBg', }, { width: 320, height: 304, - hashFunction: 'keccak256(bytes)', - hash: '0xd22a272ff5b257056cc302bcdcca1c0ea00bf912aef310eb3fa7556696b1e780', + verificationFunction: 'keccak256(bytes)', + verificationData: + '0xd22a272ff5b257056cc302bcdcca1c0ea00bf912aef310eb3fa7556696b1e780', url: 'ipfs://QmRr2urTVi12VzYa5cSHDjJXACfapaeGZW2BuNmQ8rHjCG', }, { width: 180, height: 171, - hashFunction: 'keccak256(bytes)', - hash: '0xf80d0c1492de5e148392b3a724739682e9b9564ef5fb97c06c1574bbb5e5f340', + verificationFunction: 'keccak256(bytes)', + verificationData: + '0xf80d0c1492de5e148392b3a724739682e9b9564ef5fb97c06c1574bbb5e5f340', url: 'ipfs://QmVeFyhHtdXR34UZanqU2qSuBTfGtBraG7hhN5byjJNAY5', }, ], @@ -98,21 +103,23 @@ export const profileJson = { { width: 1800, height: 1013, - hashFunction: 'keccak256(bytes)', - hash: '0x98fe032f81c43426fbcfb21c780c879667a08e2a65e8ae38027d4d61cdfe6f55', + verificationFunction: 'keccak256(bytes)', + verificationData: + '0x98fe032f81c43426fbcfb21c780c879667a08e2a65e8ae38027d4d61cdfe6f55', url: 'ipfs://QmPJESHbVkPtSaHntNVY5F6JDLW8v69M2d6khXEYGUMn7N', }, { width: 1024, height: 576, - hashFunction: 'keccak256(bytes)', - hash: '0xfce1c7436a77a009a97e48e4e10c92e89fd95fe1556fc5c62ecef57cea51aa37', + verificationFunction: 'keccak256(bytes)', + verificationData: + '0xfce1c7436a77a009a97e48e4e10c92e89fd95fe1556fc5c62ecef57cea51aa37', url: 'ipfs://QmZc9uMJxyUeUpuowJ7AD6MKoNTaWdVNcBj72iisRyM9Su', }, { width: 640, height: 360, - hashFunction: 'keccak256(bytes)', + verificationFunction: 'keccak256(bytes)', hash: '0x10a5cf2479992f1c555ad71e0a2866827f66fef6941a0c99f8d3b03e6b8b4009', url: 'ipfs://QmbP3eTmUx1UQ2eZ8hrDz8j98yP2CTmsJvfp72LZKnkKj1', }, diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 4915183d..468774e3 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -104,22 +104,22 @@ export const METHODS: Record = { }, }; -export enum SUPPORTED_HASH_FUNCTION_STRINGS { +export enum SUPPORTED_VERIFICATION_FUNCTION_STRINGS { KECCAK256_UTF8 = 'keccak256(utf8)', KECCAK256_BYTES = 'keccak256(bytes)', } -export enum SUPPORTED_HASH_FUNCTION_HASHES { +export enum SUPPORTED_VERIFICATION_FUNCTION_HASHES { HASH_KECCAK256_UTF8 = '0x6f357c6a', HASH_KECCAK256_BYTES = '0x8019f9b1', } -export type SUPPORTED_HASH_FUNCTIONS = - | SUPPORTED_HASH_FUNCTION_STRINGS - | SUPPORTED_HASH_FUNCTION_HASHES; +export type SUPPORTED_VERIFICATION_FUNCTIONS = + | SUPPORTED_VERIFICATION_FUNCTION_STRINGS + | SUPPORTED_VERIFICATION_FUNCTION_HASHES; -export const SUPPORTED_HASH_FUNCTIONS_LIST = Object.values( - SUPPORTED_HASH_FUNCTION_STRINGS, +export const SUPPORTED_VERIFICATION_FUNCTIONS_LIST = Object.values( + SUPPORTED_VERIFICATION_FUNCTION_STRINGS, ); function keccak256Utf8(data) { @@ -128,27 +128,28 @@ function keccak256Utf8(data) { const KECCAK256_UTF8 = { method: keccak256Utf8, - name: SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_UTF8, - sig: SUPPORTED_HASH_FUNCTION_HASHES.HASH_KECCAK256_UTF8, + name: SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_UTF8, + sig: SUPPORTED_VERIFICATION_FUNCTION_HASHES.HASH_KECCAK256_UTF8, }; const KECCAK256_BYTES = { method: keccak256, - name: SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_BYTES, - sig: SUPPORTED_HASH_FUNCTION_HASHES.HASH_KECCAK256_BYTES, + name: SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_BYTES, + sig: SUPPORTED_VERIFICATION_FUNCTION_HASHES.HASH_KECCAK256_BYTES, }; export const HASH_FUNCTIONS: { [key: string]: { method: Function; - name: SUPPORTED_HASH_FUNCTION_STRINGS; - sig: SUPPORTED_HASH_FUNCTIONS; + name: SUPPORTED_VERIFICATION_FUNCTION_STRINGS; + sig: SUPPORTED_VERIFICATION_FUNCTIONS; }; } = { - [SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_UTF8]: KECCAK256_UTF8, - [SUPPORTED_HASH_FUNCTION_HASHES.HASH_KECCAK256_UTF8]: KECCAK256_UTF8, - [SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_BYTES]: KECCAK256_BYTES, - [SUPPORTED_HASH_FUNCTION_HASHES.HASH_KECCAK256_BYTES]: KECCAK256_BYTES, + [SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_UTF8]: KECCAK256_UTF8, + [SUPPORTED_VERIFICATION_FUNCTION_HASHES.HASH_KECCAK256_UTF8]: KECCAK256_UTF8, + [SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_BYTES]: KECCAK256_BYTES, + [SUPPORTED_VERIFICATION_FUNCTION_HASHES.HASH_KECCAK256_BYTES]: + KECCAK256_BYTES, }; // TODO: These values can be imported from lsp-smartcontracts lib after release diff --git a/src/index.test.ts b/src/index.test.ts index 93aef0b0..6081a1b3 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -45,7 +45,7 @@ import 'isomorphic-fetch'; import { ERC725Y_INTERFACE_IDS, - SUPPORTED_HASH_FUNCTION_STRINGS, + SUPPORTED_VERIFICATION_FUNCTION_STRINGS, } from './constants/constants'; import { decodeKey } from './lib/decodeData'; import { INTERFACE_IDS_0_12_0 } from './constants/interfaces'; @@ -271,8 +271,9 @@ describe('Running @erc725/erc725.js tests...', () => { name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - hashFunction: 'keccak256(utf8)', - hash: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', + verificationFunction: 'keccak256(utf8)', + verificationData: + '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', url: 'ipfs://QmecrGejUQVXpW4zS948pNvcnQrJ1KiAoM6bdfrVcWZsn5', }, }, @@ -370,8 +371,9 @@ describe('Running @erc725/erc725.js tests...', () => { name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - hashFunction: 'keccak256(utf8)', - hash: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', + verificationFunction: 'keccak256(utf8)', + verificationData: + '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', url: 'ipfs://QmecrGejUQVXpW4zS948pNvcnQrJ1KiAoM6bdfrVcWZsn5', }, }, @@ -678,8 +680,8 @@ describe('Running @erc725/erc725.js tests...', () => { // Encoded value of: // { - // hashFunction: 'keccak256(bytes)', // 0x8019f9b1 - // hash: '0xc41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec', + // verificationFunction: 'keccak256(bytes)', // 0x8019f9b1 + // verificationData: '0xc41589e7559804ea4a2080dad19d876a024ccb05117835447d72ce08c1d020ec', // url: 'ipfs://QmYo8yg4zzmdu26NSvtsoKeU5oVR6h2ohmoa2Cx5i91mPf', // }, ], @@ -971,15 +973,17 @@ describe('Running @erc725/erc725.js tests...', () => { { width: 1350, height: 1800, - hashFunction: 'keccak256(bytes)', - hash: '0x229b60ea5b58e1ab8e6f1063300be110bb4fa663ba75d3814d60104ac6b74497', + verificationFunction: 'keccak256(bytes)', + verificationData: + '0x229b60ea5b58e1ab8e6f1063300be110bb4fa663ba75d3814d60104ac6b74497', url: 'ipfs://Qmbv9j6iCDDYJ1NXHTZnNHDJ6qaaKkZsf79jhUMFAXcfDR', }, { width: 768, height: 1024, - hashFunction: 'keccak256(bytes)', - hash: '0x320db57770084f114988c8a94bcf219ca66c69421590466a45f382cd84995c2b', + verificationFunction: 'keccak256(bytes)', + verificationData: + '0x320db57770084f114988c8a94bcf219ca66c69421590466a45f382cd84995c2b', url: 'ipfs://QmS4m2LmRpay7Jij4DCpvaW5zKZYy43ATZdRxUkUND6nG3', }, ], @@ -987,15 +991,17 @@ describe('Running @erc725/erc725.js tests...', () => { { width: 1024, height: 768, - hashFunction: 'keccak256(bytes)', - hash: '0xbe2d39fe1e0b1911155afc74010db3483528a2b645dea8fcf47bdc34147769be', + verificationFunction: 'keccak256(bytes)', + verificationData: + '0xbe2d39fe1e0b1911155afc74010db3483528a2b645dea8fcf47bdc34147769be', url: 'ipfs://QmQ6ujfKSc91F44KtMe6WRTSCXoSdCjomQUy8hCUxHMr28', }, { width: 640, height: 480, - hashFunction: 'keccak256(bytes)', - hash: '0xb115f2bf09994e79726db27a7b8d5a0de41a5b81d11b59b3038fa158718266ff', + verificationFunction: 'keccak256(bytes)', + verificationData: + '0xb115f2bf09994e79726db27a7b8d5a0de41a5b81d11b59b3038fa158718266ff', url: 'ipfs://QmakaRZxJMMqwQFJY98J3wjbqYVDnaSZ9sEqBF9iMv3GNX', }, ], @@ -1025,12 +1031,12 @@ describe('Running @erc725/erc725.js tests...', () => { 'ipfs://QmbKvCVEePiDKxuouyty9bMsWBAxZDGr2jhxd4pLGLx95D', ); assert.deepStrictEqual( - decodedData[0].value.hash, - hashData(json, SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_UTF8), + decodedData[0].value.verificationData, + hashData(json, SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_UTF8), ); assert.deepStrictEqual( - decodedData[0].value.hashFunction, - SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_UTF8, + decodedData[0].value.verificationFunction, + SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_UTF8, ); }); diff --git a/src/lib/encoder.test.ts b/src/lib/encoder.test.ts index b425bcf0..9200705f 100644 --- a/src/lib/encoder.test.ts +++ b/src/lib/encoder.test.ts @@ -26,8 +26,8 @@ import { decodeValueContent, } from './encoder'; import { - SUPPORTED_HASH_FUNCTION_HASHES, - SUPPORTED_HASH_FUNCTION_STRINGS, + SUPPORTED_VERIFICATION_FUNCTION_HASHES, + SUPPORTED_VERIFICATION_FUNCTION_STRINGS, } from '../constants/constants'; import { JSONURLDataToEncode, URLDataWithHash } from '../types'; @@ -867,8 +867,10 @@ describe('encoder', () => { { valueContent: 'AssetURL', decodedValue: { - hashFunction: SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_UTF8, - hash: '0x027547537d35728a741470df1ccf65de10b454ca0def7c5c20b257b7b8d16168', + verificationFunction: + SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_UTF8, + verificationData: + '0x027547537d35728a741470df1ccf65de10b454ca0def7c5c20b257b7b8d16168', url: 'http://test.com/asset.glb', }, encodedValue: @@ -922,19 +924,21 @@ describe('encoder', () => { }; const encodedValue = encodeValueContent('JSONURL', dataToEncode); - const hashFunction = SUPPORTED_HASH_FUNCTION_HASHES.HASH_KECCAK256_UTF8; + const verificationFunction = + SUPPORTED_VERIFICATION_FUNCTION_HASHES.HASH_KECCAK256_UTF8; const hexUrl = utf8ToHex(dataToEncode.url).substring(2); - const jsonDataHash = keccak256( + const jsonVerificationData = keccak256( JSON.stringify(dataToEncode.json), ).substring(2); assert.deepStrictEqual( encodedValue, - hashFunction + jsonDataHash + hexUrl, + verificationFunction + jsonVerificationData + hexUrl, ); const expectedDecodedValue: URLDataWithHash = { - hash: `0x${jsonDataHash}`, - hashFunction: SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_UTF8, + verificationData: `0x${jsonVerificationData}`, + verificationFunction: + SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_UTF8, url: dataToEncode.url, }; @@ -977,37 +981,37 @@ describe('encoder', () => { }); describe('JSONURL', () => { - it('throws when the hashFunction of JSON of JSONURL to encode is not keccak256(utf8)', () => { + it('throws when the verificationFunction of JSON of JSONURL to encode is not keccak256(utf8)', () => { assert.throws( () => { valueContentEncodingMap('JSONURL').encode({ // @ts-ignore to still run the test (incase someone is using the library in a non TS environment) - hashFunction: 'whatever', + verificationFunction: 'whatever', url: 'https://file-desination.com/file-name', - hash: '0x321', + verificationData: '0x321', }); }, (error: any) => { return ( error.message === - `Chosen hashFunction 'whatever' is not supported. Supported hashFunctions: keccak256(utf8),keccak256(bytes)` + `Chosen verificationFunction 'whatever' is not supported. Supported verificationFunctions: keccak256(utf8),keccak256(bytes)` ); }, ); }); - it('throws when JSONURL encode a JSON without json or hash key', () => { + it('throws when JSONURL encode a JSON without json or verificationData key', () => { assert.throws( () => { valueContentEncodingMap('JSONURL').encode({ // @ts-ignore to still run the test (incase someone is using the library in a non TS environment) - hashFunction: 'keccak256(utf8)', + verificationFunction: 'keccak256(utf8)', url: 'https://file-desination.com/file-name', }); }, (error: any) => error.message === - 'You have to provide either the hash or the json via the respective properties', + 'You have to provide either the verificationData or the json via the respective properties', ); }); }); diff --git a/src/lib/encoder.ts b/src/lib/encoder.ts index bde305fc..f9f27e97 100644 --- a/src/lib/encoder.ts +++ b/src/lib/encoder.ts @@ -48,10 +48,10 @@ import { JSONURLDataToEncode, URLDataWithHash } from '../types'; import { AssetURLEncode } from '../types/encodeData'; import { - SUPPORTED_HASH_FUNCTIONS, - SUPPORTED_HASH_FUNCTION_STRINGS, + SUPPORTED_VERIFICATION_FUNCTIONS, + SUPPORTED_VERIFICATION_FUNCTION_STRINGS, } from '../constants/constants'; -import { getHashFunction, hashData, countNumberOfBytes } from './utils'; +import { getVerificationFunction, hashData, countNumberOfBytes } from './utils'; const abiCoder = AbiCoder; @@ -60,28 +60,32 @@ const bytesNRegex = /Bytes(\d+)/; const ALLOWED_BYTES_SIZES = [2, 4, 8, 16, 32, 64, 128, 256]; const encodeDataSourceWithHash = ( - hashType: SUPPORTED_HASH_FUNCTIONS, + hashType: SUPPORTED_VERIFICATION_FUNCTIONS, dataHash: string, dataSource: string, ): string => { - const hashFunction = getHashFunction(hashType); + const verificationFunction = getVerificationFunction(hashType); return ( - keccak256(hashFunction.name).slice(0, 10) + + keccak256(verificationFunction.name).slice(0, 10) + dataHash.slice(2) + utf8ToHex(dataSource).slice(2) ); }; const decodeDataSourceWithHash = (value: string): URLDataWithHash => { - const hashFunctionSig = value.slice(0, 10); - const hashFunction = getHashFunction(hashFunctionSig); + const verificationFunctionSig = value.slice(0, 10); + const verificationFunction = getVerificationFunction(verificationFunctionSig); const encodedData = value.replace('0x', '').slice(8); // Rest of data string after function hash const dataHash = '0x' + encodedData.slice(0, 64); // Get jsonHash 32 bytes const dataSource = hexToUtf8('0x' + encodedData.slice(64)); // Get remainder as URI - return { hashFunction: hashFunction.name, hash: dataHash, url: dataSource }; + return { + verificationFunction: verificationFunction.name, + verificationData: dataHash, + url: dataSource, + }; }; const encodeToBytesN = ( @@ -563,7 +567,11 @@ export const valueContentEncodingMap = (valueContent: string) => { return { type: 'custom', encode: (value: AssetURLEncode) => - encodeDataSourceWithHash(value.hashFunction, value.hash, value.url), + encodeDataSourceWithHash( + value.verificationFunction, + value.verificationData, + value.url, + ), decode: (value: string) => decodeDataSourceWithHash(value), }; } @@ -572,31 +580,32 @@ export const valueContentEncodingMap = (valueContent: string) => { return { type: 'custom', encode: (dataToEncode: JSONURLDataToEncode) => { - const { hash, json, hashFunction, url } = dataToEncode; + const { verificationData, json, verificationFunction, url } = + dataToEncode; - let hashedJson = hash; + let hashedJson = verificationData; if (json) { - if (hashFunction) { + if (verificationFunction) { throw new Error( - 'When passing in the `json` property, we use "keccak256(utf8)" as a default hashingFunction. You do not need to set a `hashFunction`.', + 'When passing in the `json` property, we use "keccak256(utf8)" as a default verificationFunction. You do not need to set a `verificationFunction`.', ); } hashedJson = hashData( json, - SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_UTF8, + SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_UTF8, ); } if (!hashedJson) { throw new Error( - 'You have to provide either the hash or the json via the respective properties', + 'You have to provide either the verificationData or the json via the respective properties', ); } return encodeDataSourceWithHash( - (hashFunction as SUPPORTED_HASH_FUNCTION_STRINGS) || - SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_UTF8, + (verificationFunction as SUPPORTED_VERIFICATION_FUNCTION_STRINGS) || + SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_UTF8, hashedJson, url, ); diff --git a/src/lib/getDataFromExternalSources.ts b/src/lib/getDataFromExternalSources.ts index 62592dca..505a42f0 100644 --- a/src/lib/getDataFromExternalSources.ts +++ b/src/lib/getDataFromExternalSources.ts @@ -25,8 +25,8 @@ import { } from '../types/decodeData'; import { ERC725JSONSchema } from '../types/ERC725JSONSchema'; import { - SUPPORTED_HASH_FUNCTIONS, - SUPPORTED_HASH_FUNCTION_STRINGS, + SUPPORTED_VERIFICATION_FUNCTIONS, + SUPPORTED_VERIFICATION_FUNCTION_STRINGS, } from '../constants/constants'; import { isDataAuthentic, patchIPFSUrlsIfApplicable } from './utils'; @@ -81,8 +81,8 @@ export const getDataFromExternalSources = ( receivedData = await fetch(url).then(async (response) => { if ( - urlDataWithHash.hashFunction === - SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_BYTES + urlDataWithHash.verificationFunction === + SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_BYTES ) { return response .arrayBuffer() @@ -98,8 +98,8 @@ export const getDataFromExternalSources = ( return isDataAuthentic( receivedData, - urlDataWithHash.hash, - urlDataWithHash.hashFunction as SUPPORTED_HASH_FUNCTIONS, + urlDataWithHash.verificationData, + urlDataWithHash.verificationFunction as SUPPORTED_VERIFICATION_FUNCTIONS, ) ? { ...dataEntry, value: receivedData } : { ...dataEntry, value: null }; diff --git a/src/lib/utils.test.ts b/src/lib/utils.test.ts index 3365d600..facef7f7 100644 --- a/src/lib/utils.test.ts +++ b/src/lib/utils.test.ts @@ -25,7 +25,7 @@ import { } from '../types/ERC725JSONSchema'; import { GetDataDynamicKey } from '../types/GetData'; -import { SUPPORTED_HASH_FUNCTION_STRINGS } from '../constants/constants'; +import { SUPPORTED_VERIFICATION_FUNCTION_STRINGS } from '../constants/constants'; import { guessKeyTypeFromKeyName, isDataAuthentic, @@ -81,13 +81,17 @@ describe('utils', () => { }, decodedValue: [ { - hashFunction: SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_UTF8, - hash: '0x733e78f2fc4a3304c141e8424d02c9069fe08950c6514b27289ead8ef4faa49d', + verificationFunction: + SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_UTF8, + verificationData: + '0x733e78f2fc4a3304c141e8424d02c9069fe08950c6514b27289ead8ef4faa49d', url: 'ipfs://QmbErKh3FjsAR6YjsTjHZNm6McDp6aRt82Ftcv9AJJvZbd', }, { - hashFunction: SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_UTF8, - hash: '0x81bd0b7ed5ac354abbf24619ce16933f00a4bdfa8fcaf3791d25f69b497abf88', + verificationFunction: + SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_UTF8, + verificationData: + '0x81bd0b7ed5ac354abbf24619ce16933f00a4bdfa8fcaf3791d25f69b497abf88', url: 'ipfs://QmbErKh3Fjsxxxxxxxxxxxxxxxxxxxxxxxxxxv9AJJvZbd', }, ], @@ -288,8 +292,10 @@ describe('utils', () => { valueContent: 'AssetURL', valueType: 'bytes', decodedValue: { - hashFunction: SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_UTF8, - hash: '0x81dadadadadadadadadadadadadadadf00a4bdfa8fcaf3791d25f69b497abf88', + verificationFunction: + SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_UTF8, + verificationData: + '0x81dadadadadadadadadadadadadadadf00a4bdfa8fcaf3791d25f69b497abf88', url: 'http://day.night/asset.glb', }, encodedValue: @@ -299,8 +305,10 @@ describe('utils', () => { valueContent: 'JSONURL', valueType: 'bytes', decodedValue: { - hashFunction: SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_UTF8, - hash: '0x81bd0b7ed5ac354abbf24619ce16933f00a4bdfa8fcaf3791d25f69b497abf88', + verificationFunction: + SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_UTF8, + verificationData: + '0x81bd0b7ed5ac354abbf24619ce16933f00a4bdfa8fcaf3791d25f69b497abf88', url: 'ipfs://QmbErKh3Fjsxxxxxxxxxxxxxxxxxxxxxxxxxxv9AJJvZbd', }, encodedValue: @@ -565,8 +573,9 @@ describe('utils', () => { { keyName: 'LSP3Profile', value: { - hashFunction: 'keccak256(utf8)', - hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', + verificationFunction: 'keccak256(utf8)', + verificationData: + '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx', }, }, @@ -658,7 +667,7 @@ describe('utils', () => { const isAuthentic = isDataAuthentic( data, expectedHash, - SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_BYTES, + SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_BYTES, ); assert.ok(isAuthentic); @@ -670,7 +679,7 @@ describe('utils', () => { const isAuthentic = isDataAuthentic( data, expectedHash, - SUPPORTED_HASH_FUNCTION_STRINGS.KECCAK256_BYTES, + SUPPORTED_VERIFICATION_FUNCTION_STRINGS.KECCAK256_BYTES, ); assert.strictEqual(isAuthentic, false); diff --git a/src/lib/utils.ts b/src/lib/utils.ts index f289fb01..ab4a4edf 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -41,8 +41,8 @@ import { import { HASH_FUNCTIONS, - SUPPORTED_HASH_FUNCTIONS, - SUPPORTED_HASH_FUNCTIONS_LIST, + SUPPORTED_VERIFICATION_FUNCTIONS, + SUPPORTED_VERIFICATION_FUNCTIONS_LIST, COMPACT_BYTES_ARRAY_STRING, } from '../constants/constants'; import { @@ -468,25 +468,29 @@ export function encodeData( ); } -export function getHashFunction(hashFunctionNameOrHash: string) { - const hashFunction = HASH_FUNCTIONS[hashFunctionNameOrHash]; +export function getVerificationFunction( + verificationFunctionNameOrHash: string, +) { + const verificationFunction = HASH_FUNCTIONS[verificationFunctionNameOrHash]; - if (!hashFunction) { + if (!verificationFunction) { throw new Error( - `Chosen hashFunction '${hashFunctionNameOrHash}' is not supported. Supported hashFunctions: ${SUPPORTED_HASH_FUNCTIONS_LIST}`, + `Chosen verificationFunction '${verificationFunctionNameOrHash}' is not supported. Supported verificationFunctions: ${SUPPORTED_VERIFICATION_FUNCTIONS_LIST}`, ); } - return hashFunction; + return verificationFunction; } export function hashData( data: string | Uint8Array | Record, - hashFunctionNameOrHash: SUPPORTED_HASH_FUNCTIONS, + verificationFunctionNameOrHash: SUPPORTED_VERIFICATION_FUNCTIONS, ): string { - const hashFunction = getHashFunction(hashFunctionNameOrHash); + const verificationFunction = getVerificationFunction( + verificationFunctionNameOrHash, + ); - return hashFunction.method(data); + return verificationFunction.method(data); } /** @@ -496,14 +500,14 @@ export function hashData( export function isDataAuthentic( data: string | Uint8Array, expectedHash: string, - lowerCaseHashFunction: SUPPORTED_HASH_FUNCTIONS, + lowerCaseVerificationFunction: SUPPORTED_VERIFICATION_FUNCTIONS, ): boolean { let dataHash: string; if (data instanceof Uint8Array) { - dataHash = hashData(arrToBufArr(data), lowerCaseHashFunction); + dataHash = hashData(arrToBufArr(data), lowerCaseVerificationFunction); } else { - dataHash = hashData(data, lowerCaseHashFunction); + dataHash = hashData(data, lowerCaseVerificationFunction); } if (dataHash !== expectedHash) { diff --git a/src/types/encodeData/JSONURL.ts b/src/types/encodeData/JSONURL.ts index 842dc380..13b6ccfa 100644 --- a/src/types/encodeData/JSONURL.ts +++ b/src/types/encodeData/JSONURL.ts @@ -1,4 +1,4 @@ -import { SUPPORTED_HASH_FUNCTIONS } from '../../constants/constants'; +import { SUPPORTED_VERIFICATION_FUNCTIONS } from '../../constants/constants'; export interface KeyValuePair { key: string; @@ -10,14 +10,14 @@ interface URLData { } export interface URLDataWithHash extends URLData { - hash: string; - hashFunction: SUPPORTED_HASH_FUNCTIONS | string; // | string is to allow use of string directly without importing the enum + verificationData: string; + verificationFunction: SUPPORTED_VERIFICATION_FUNCTIONS | string; // | string is to allow use of string directly without importing the enum json?: never; } export interface URLDataWithJson extends URLData { - hash?: never; - hashFunction?: never; + verificationData?: never; + verificationFunction?: never; json: Record; } diff --git a/src/types/encodeData/index.ts b/src/types/encodeData/index.ts index 44f1e05e..a20a2174 100644 --- a/src/types/encodeData/index.ts +++ b/src/types/encodeData/index.ts @@ -1,7 +1,7 @@ -import { SUPPORTED_HASH_FUNCTIONS } from '../../constants/constants'; +import { SUPPORTED_VERIFICATION_FUNCTIONS } from '../../constants/constants'; export interface AssetURLEncode { - hashFunction: SUPPORTED_HASH_FUNCTIONS; - hash: string; + verificationFunction: SUPPORTED_VERIFICATION_FUNCTIONS; + verificationData: string; url: string; } diff --git a/test/mockSchema.ts b/test/mockSchema.ts index f434d447..1988c8fe 100644 --- a/test/mockSchema.ts +++ b/test/mockSchema.ts @@ -47,8 +47,9 @@ export const mockSchema: (ERC725JSONSchema & { returnGraphData: '0x6f357c6a733e78f2fc4a3304c141e8424d02c9069fe08950c6514b27289ead8ef4faa49d697066733a2f2f516d6245724b6833466a73415236596a73546a485a4e6d364d6344703661527438324674637639414a4a765a6264', expectedResult: { - hashFunction: 'keccak256(utf8)', - hash: '0x733e78f2fc4a3304c141e8424d02c9069fe08950c6514b27289ead8ef4faa49d', // hash of stringified json + verificationFunction: 'keccak256(utf8)', + verificationData: + '0x733e78f2fc4a3304c141e8424d02c9069fe08950c6514b27289ead8ef4faa49d', // hash of stringified json url: 'ipfs://QmbErKh3FjsAR6YjsTjHZNm6McDp6aRt82Ftcv9AJJvZbd', // same JSON url from LSP3Profile below }, }, @@ -71,8 +72,9 @@ export const mockSchema: (ERC725JSONSchema & { returnGraphData: '0x6f357c6aa7d9a84b44013f71356d72e6c15fdc2533c573271c53d053ed8ddcdaa60f4c81697066733a2f2f516d6245724b6833466a73415236596a73546a485a4e6d364d6344703661527438324674637639414a4a765a6264', expectedResult: { - hashFunction: 'keccak256(utf8)', - hash: '0xa7d9a84b44013f71356d72e6c15fdc2533c573271c53d053ed8ddcdaa60f4c81', // hash of address '0x0c03fba782b07bcf810deb3b7f0595024a444f4e' + verificationFunction: 'keccak256(utf8)', + verificationData: + '0xa7d9a84b44013f71356d72e6c15fdc2533c573271c53d053ed8ddcdaa60f4c81', // hash of address '0x0c03fba782b07bcf810deb3b7f0595024a444f4e' url: 'ipfs://QmbErKh3FjsAR6YjsTjHZNm6McDp6aRt82Ftcv9AJJvZbd', // FAKE. just used from above TODO: fix this is not an asset URL but a JSON url !! }, }, @@ -283,14 +285,16 @@ export const mockSchema: (ERC725JSONSchema & { expectedResult: [ // This JSON from JSONURL above... { - hashFunction: 'keccak256(utf8)', - hash: '0x733e78f2fc4a3304c141e8424d02c9069fe08950c6514b27289ead8ef4faa49d', // hash of stringified json + verificationFunction: 'keccak256(utf8)', + verificationData: + '0x733e78f2fc4a3304c141e8424d02c9069fe08950c6514b27289ead8ef4faa49d', // hash of stringified json url: 'ipfs://QmbErKh3FjsAR6YjsTjHZNm6McDp6aRt82Ftcv9AJJvZbd', // same JSON url from LSP3Profile below }, // this JSON hash is = {"test1":"value1","test2":"value2","test3":"value3"} { - hashFunction: 'keccak256(utf8)', - hash: '0x81bd0b7ed5ac354abbf24619ce16933f00a4bdfa8fcaf3791d25f69b497abf88', // hash of stringified json + verificationFunction: 'keccak256(utf8)', + verificationData: + '0x81bd0b7ed5ac354abbf24619ce16933f00a4bdfa8fcaf3791d25f69b497abf88', // hash of stringified json url: 'ipfs://QmbErKh3Fjsxxxxxxxxxxxxxxxxxxxxxxxxxxv9AJJvZbd', // dummy url }, ], @@ -608,8 +612,9 @@ export const mockSchema: (ERC725JSONSchema & { ]), returnGraphData: '0x0c03fba782b07bcf810deb3b7f0595024a444f4e', expectedResult: { - hashFunction: 'keccak256(utf8)', - hash: '0xa7d9a84b44013f71356d72e6c15fdc2533c573271c53d053ed8ddcdaa60f4c81', // hash of address '0x0c03fba782b07bcf810deb3b7f0595024a444f4e' + verificationFunction: 'keccak256(utf8)', + verificationData: + '0xa7d9a84b44013f71356d72e6c15fdc2533c573271c53d053ed8ddcdaa60f4c81', // hash of address '0x0c03fba782b07bcf810deb3b7f0595024a444f4e' url: 'ipfs://QmbErKh3FjsAR6YjsTjHZNm6McDp6aRt82Ftcv9AJJvZbd', // FAKE. just used from above TODO: fix this is not an asset URL but a JSON url !! }, }, From 035591e36a9b6ee8d8f1ad202bde8a947453886f Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Tue, 31 Oct 2023 16:22:56 +0100 Subject: [PATCH 05/10] typo --- README.md | 4 ++-- examples/src/decodeData.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d8f9131f..373137fe 100644 --- a/README.md +++ b/README.md @@ -118,8 +118,8 @@ await myErc725.getData(); name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - validationFunction: 'keccak256(utf8)', - validation: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', + verificationFunction: 'keccak256(utf8)', + verification: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', url: 'ipfs://QmecrGejUQVXpW4zS948pNvcnQrJ1KiAoM6bdfrVcWZsn5', }, }, diff --git a/examples/src/decodeData.js b/examples/src/decodeData.js index 0bc5551d..b10fd05a 100644 --- a/examples/src/decodeData.js +++ b/examples/src/decodeData.js @@ -17,8 +17,8 @@ const decodedDataOneKey = myERC725.decodeData([ name: 'LSP3Profile', key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { - validationFunction: 'keccak256(utf8)', - validation: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', + verificationFunction: 'keccak256(utf8)', + verificationData: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx' } } From a7c60d0c8928c5bd1adcdebfc4413f6f9768cabe Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Thu, 2 Nov 2023 09:29:33 +0100 Subject: [PATCH 06/10] removed remaining hash --- README.md | 2 +- docs/getting-started.md | 2 +- examples/src/instantiation.js | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 373137fe..c864e288 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ await myErc725.getData(); key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5', value: { verificationFunction: 'keccak256(utf8)', - verification: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', + verificationData: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3', url: 'ipfs://QmecrGejUQVXpW4zS948pNvcnQrJ1KiAoM6bdfrVcWZsn5', }, }, diff --git a/docs/getting-started.md b/docs/getting-started.md index b05207ee..da6b1e98 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -84,7 +84,7 @@ await erc725.getData(['LSP3Profile', 'SupportedStandards:LSP3Profile']); { LSP3Profile: { url: 'ipfs://QmXybv2LdJWscy1C6yRKUjvnaj6aqKktZX4g4xmz2nyYj2', - hash: '0xb4f9d72e83bbe7e250ed9ec80332c493b7b3d73e0d72f7b2c7ab01c39216eb1a', + verificationData: '0xb4f9d72e83bbe7e250ed9ec80332c493b7b3d73e0d72f7b2c7ab01c39216eb1a', verificationFunction: 'keccak256(utf8)' }, 'SupportedStandards:LSP3Profile': '0x5ef83ad9' diff --git a/examples/src/instantiation.js b/examples/src/instantiation.js index 54915414..21c05cec 100644 --- a/examples/src/instantiation.js +++ b/examples/src/instantiation.js @@ -120,7 +120,8 @@ export const profileJson = { width: 640, height: 360, verificationFunction: 'keccak256(bytes)', - hash: '0x10a5cf2479992f1c555ad71e0a2866827f66fef6941a0c99f8d3b03e6b8b4009', + verificationData: + '0x10a5cf2479992f1c555ad71e0a2866827f66fef6941a0c99f8d3b03e6b8b4009', url: 'ipfs://QmbP3eTmUx1UQ2eZ8hrDz8j98yP2CTmsJvfp72LZKnkKj1', }, ], From ca39593f061fbc532823c6fa01393fe22046f08f Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Thu, 2 Nov 2023 13:07:26 +0100 Subject: [PATCH 07/10] change default gas value to 1_000_000 & update interface --- docs/classes/ERC725.md | 2 +- docs/getting-started.md | 2 +- src/constants/constants.ts | 2 +- src/index.ts | 2 +- src/provider/providerWrapper.test.ts | 2 +- src/types/Config.ts | 6 ++++-- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/classes/ERC725.md b/docs/classes/ERC725.md index 48985771..bf276aca 100644 --- a/docs/classes/ERC725.md +++ b/docs/classes/ERC725.md @@ -1446,7 +1446,7 @@ On non instantiated class, you should provide an `options` object. | :-------- | :----- | :------------------------------------------------------------------- | | `address` | string | Address of the smart contract to check against a certain interface. | | `rpcUrl` | string | RPC URL to connect to the network the smart contract is deployed to. | -| `gas` | number | Optional: gas parameter to use. Default: 2_000_000. | +| `gas` | number | Optional: gas parameter to use. Default: 1_000_000. | #### Returns diff --git a/docs/getting-started.md b/docs/getting-started.md index 71b05e92..e2e0a4ed 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -61,7 +61,7 @@ const address = '0x0Dc07C77985fE31996Ed612F568eb441afe5768D'; const RPC_URL = 'https://rpc.testnet.lukso.network'; const config = { ipfsGateway: 'https://YOUR-IPFS-GATEWAY/ipfs/', - gas: 20_000_000, // optional, default is 2_000_000 + gas: 20_000_000, // optional, default is 1_000_000 }; const erc725 = new ERC725(schemas, address, RPC_URL, config); diff --git a/src/constants/constants.ts b/src/constants/constants.ts index c9948fc9..5a9ce435 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -172,4 +172,4 @@ export const LSP6_ALL_PERMISSIONS = export const COMPACT_BYTES_ARRAY_STRING = '[CompactBytesArray]'; -export const DEFAULT_GAS_VALUE = 2_000_000; +export const DEFAULT_GAS_VALUE = 1_000_000; diff --git a/src/index.ts b/src/index.ts index ec12ebbe..4d37d9be 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,7 +81,7 @@ export { encodeData } from './lib/utils'; * */ export class ERC725 { - options: ERC725Options & ERC725Config; + options: ERC725Options; /** * Creates an instance of ERC725. diff --git a/src/provider/providerWrapper.test.ts b/src/provider/providerWrapper.test.ts index 75e8ed94..fa655712 100644 --- a/src/provider/providerWrapper.test.ts +++ b/src/provider/providerWrapper.test.ts @@ -3,7 +3,7 @@ import assert from 'assert'; import { ProviderWrapper } from './providerWrapper'; const erc725AccountAddress = '0x214be121bB52e6909c5158579b3458f8760f1b2f'; -const defaultGas = 2_000_000; +const defaultGas = 1_000_000; describe('ProviderWrapper', () => { describe('#getOwner', () => { diff --git a/src/types/Config.ts b/src/types/Config.ts index 15707591..dd592c49 100644 --- a/src/types/Config.ts +++ b/src/types/Config.ts @@ -5,13 +5,13 @@ export interface ERC725Config { * ```js title=Example * const config = { * ipfsGateway: 'https://ipfs.lukso.network/ipfs/' - * gas: 20_000_000 // Optional, default 2_000_000 + * gas: 20_000_000 // Optional, default 0 * }; * ``` * Make sure to use the following format: `/ipfs/`.
* Another example: `https://cloudflare-ipfs.com/ipfs/` */ - ipfsGateway: string; + ipfsGateway?: string; gas?: number; } @@ -19,4 +19,6 @@ export interface ERC725Options { schemas: ERC725JSONSchema[]; address?: string; provider?; + ipfsGateway: string; + gas: number; } From 82e383345a712619b5c6a1030b124d2625115fc1 Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Thu, 2 Nov 2023 13:39:10 +0100 Subject: [PATCH 08/10] feat: new gas parameter From 9640d9fbf88c7cf694b9e82cc3a711350334b097 Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Thu, 2 Nov 2023 13:48:36 +0100 Subject: [PATCH 09/10] refactor!: update lsp3/lsp4 verificationData From 13bac490814e451886c933779fe461c63306aaa4 Mon Sep 17 00:00:00 2001 From: CJ42 Date: Thu, 2 Nov 2023 15:10:45 +0000 Subject: [PATCH 10/10] refactor: update LSP interface IDs --- src/constants/interfaces.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/constants/interfaces.ts b/src/constants/interfaces.ts index 25e93087..88f5338d 100644 --- a/src/constants/interfaces.ts +++ b/src/constants/interfaces.ts @@ -21,8 +21,8 @@ export const INTERFACE_IDS_0_12_0 = { LSP1UniversalReceiver: '0x6bb56a14', LSP1UniversalReceiverDelegate: '0xa245bbda', LSP6KeyManager: '0x23f34c62', - LSP7DigitalAsset: '0x05519512', - LSP8IdentifiableDigitalAsset: '0x1ae9ba1f', + LSP7DigitalAsset: '0xdaa746b7', + LSP8IdentifiableDigitalAsset: '0x30dc5278', LSP9Vault: '0x28af17e6', LSP11BasicSocialRecovery: '0x049a28f1', LSP14Ownable2Step: '0x94be5999',