Skip to content

Commit

Permalink
Merge pull request #376 from ERC725Alliance/develop
Browse files Browse the repository at this point in the history
chore: sync main
  • Loading branch information
richtera authored Jan 22, 2024
2 parents 3994b72 + e46dfd8 commit 1dd59bf
Show file tree
Hide file tree
Showing 23 changed files with 720 additions and 245 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x]
node-version: [18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
69 changes: 55 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,85 @@ If you install it on the backend side, you may need to also install [`isomorphic

## Instantiation

You need to initialise it with a [schema](https://docs.lukso.tech/tools/erc725js/schemas), a contract address and an RPC URL.
You need to initialise the ERC725 object with a [schema](https://docs.lukso.tech/tools/erc725js/schemas), a contract address, and an RPC URL.

```js
import { ERC725 } from '@erc725/erc725.js';
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 1_000_000
};
```

### TypeScript

// Part of LSP3-Profile Schema
// https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-3-Profile-Metadata.md
const schema = [
> If you are using ES6 `import` statements in Node.js, make sure your file has a `.mjs` extension, or that your project is set up to support ES6 modules.
```ts
import { ERC725, ERC725JSONSchema } from '@erc725/erc725.js';

// Part of LSP3-UniversalProfile Schema
// https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-3-UniversalProfile.md
const schemas: ERC725JSONSchema[] = [
{
name: 'SupportedStandards:LSP3Profile',
key: '0xeafec4d89fa9619884b600005ef83ad9559033e6e941db7d7c495acdce616347',
keyType: 'Mapping',
valueContent: '0x5ef83ad9',
valueType: 'bytes',
valueContent: '0x5ef83ad9',
},
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
keyType: 'Singleton',
valueContent: 'VerifiableURI',
valueType: 'bytes',
valueContent: 'VerifiableURI',
},
{
name: 'LSP1UniversalReceiverDelegate',
key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
keyType: 'Singleton',
valueContent: 'Address',
valueType: 'address',
valueContent: 'Address',
},
];

const address = '0x3000783905Cc7170cCCe49a4112Deda952DDBe24';
const RPC_URL = 'https://rpc.testnet.lukso.network';
const config = {
ipfsGateway: 'https://2eff.lukso.dev/ipfs/',
};
const erc725 = new ERC725(schemas, address, RPC_URL, config);
```

### JavaScript

```js
import { ERC725 } require('@erc725/erc725.js');

// Part of LSP3-UniversalProfile Schema
// https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-3-UniversalProfile.md
const schemas = [
{
name: 'SupportedStandards:LSP3Profile',
key: '0xeafec4d89fa9619884b600005ef83ad9559033e6e941db7d7c495acdce616347',
keyType: 'Mapping',
valueType: 'bytes',
valueContent: '0x5ef83ad9',
},
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
keyType: 'Singleton',
valueType: 'bytes',
valueContent: 'VerifiableURI',
},
{
name: 'LSP1UniversalReceiverDelegate',
key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
keyType: 'Singleton',
valueType: 'address',
valueContent: 'Address',
},
];

const myErc725 = new ERC725(schema, address, RPC_URL, config);
const erc725 = new ERC725(schemas, address, RPC_URL, config);
```

## Usage
Expand Down
3 changes: 2 additions & 1 deletion docs/classes/ERC725.md
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,8 @@ ERC725.encodePermissions({
ENCRYPT: false,
DECRYPT: false,
SIGN: false,
EXECUTE_RELAY_CALL: false
EXECUTE_RELAY_CALL: false,
ERC4337_PERMISSION: false
}),
// '0x0000000000000000000000000000000000000000000000000000000000000110'

Expand Down
58 changes: 50 additions & 8 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,27 @@ If you install it on the backend side, you may need to also install [`isomorphic

## Instantiation

You need to initialise the ERC725 object with a [schema](https://docs.lukso.tech/tools/erc725js/schemas), a contract address, and an RPC URL.

```js
import { ERC725 } from '@erc725/erc725.js';
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 1_000_000
};
```

### TypeScript

> If you are using ES6 `import` statements in Node.js, make sure your file has a `.mjs` extension, or that your project is set up to support ES6 modules.
```ts
import { ERC725, ERC725JSONSchema } from '@erc725/erc725.js';

// Part of LSP3-UniversalProfile Schema
// https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-3-UniversalProfile.md
const schemas = [
const schemas: ERC725JSONSchema[] = [
{
name: 'SupportedStandards:LSP3Profile',
key: '0xeafec4d89fa9619884b600005ef83ad9559033e6e941db7d7c495acdce616347',
Expand All @@ -56,12 +71,39 @@ const schemas = [
},
];

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 1_000_000
};
const erc725 = new ERC725(schemas, address, RPC_URL, config);
```

### JavaScript

```js
import { ERC725 } require('@erc725/erc725.js');

// Part of LSP3-UniversalProfile Schema
// https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-3-UniversalProfile.md
const schemas = [
{
name: 'SupportedStandards:LSP3Profile',
key: '0xeafec4d89fa9619884b600005ef83ad9559033e6e941db7d7c495acdce616347',
keyType: 'Mapping',
valueType: 'bytes',
valueContent: '0x5ef83ad9',
},
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
keyType: 'Singleton',
valueType: 'bytes',
valueContent: 'VerifiableURI',
},
{
name: 'LSP1UniversalReceiverDelegate',
key: '0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47',
keyType: 'Singleton',
valueType: 'address',
valueContent: 'Address',
},
];

const erc725 = new ERC725(schemas, address, RPC_URL, config);
```
Expand Down
26 changes: 23 additions & 3 deletions docs/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,29 @@ _A quick reference for keys used in schema definitions can be seen below_

## Standard LSP Schemas

The most common schemas of [LUKSO Standard Proposals](https://github.com/lukso-network/LIPs/tree/main/LSPs) are available under the [`schemas/`](https://github.com/ERC725Alliance/erc725.js/tree/develop/schemas) folder.
The most common schemas of [LUKSO Standard Proposals](https://github.com/lukso-network/LIPs/tree/main/LSPs) are available to import. These are typed automatically with the Typescript type `ERC725JSONSchema[]` for when instantiating `new ERC725(...)` from Typescript projects.

Current provided LSPs are:
```ts
import {
LSP1Schema,
LSP3Schema,
LSP4Schema,
LSP4LegacySchema,
LSP5Schema,
LSP6Schema,
LSP8Schema,
LSP9Schema,
LSP10Schema,
LSP12Schema,
LSP17Schema,
} from '@erc725/erc725.js/schemas';

const erc725js = new ERC725(LSP12Schema);
```

The raw JSON schemas are also available for import from the [`schemas/`](https://github.com/ERC725Alliance/erc725.js/tree/develop/schemas) folder.

Current provided LSPs JSON schemas are:

```
LSP1UniversalReceiverDelegate.json
Expand All @@ -38,7 +58,7 @@ LSP12IssuedAssets.json
LSP17ContractExtension.json
```

You can import them from:
You can import the raw JSON as follow:

```js
import LSP3 from '@erc725/erc725.js/schemas/LSP3ProfileMetadata.json';
Expand Down
25 changes: 19 additions & 6 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

/* eslint-disable @typescript-eslint/ban-types */
import { numberToHex, keccak256 } from 'web3-utils';
import { arrToBufArr, bufferToHex } from 'ethereumjs-util';

import { MethodData, Encoding, Method } from '../types/Method';

Expand Down Expand Up @@ -92,7 +93,7 @@ export const METHODS: Record<Method, MethodData> = {
},
};

export const UNKNOWN_VERIFICATION_METHOD = 'unknown';
export const NONE_VERIFICATION_METHOD = '0x00000000';

export enum SUPPORTED_VERIFICATION_METHOD_STRINGS {
KECCAK256_UTF8 = 'keccak256(utf8)',
Expand All @@ -112,25 +113,36 @@ export const SUPPORTED_VERIFICATION_METHODS_LIST = Object.values(
SUPPORTED_VERIFICATION_METHOD_STRINGS,
);

function keccak256Utf8(data) {
return keccak256(JSON.stringify(data));
function keccak256Method(data: object | string | Uint8Array | null) {
if (data === null) {
return keccak256('');
}
if (data instanceof Uint8Array) {
const buffer = bufferToHex(arrToBufArr(data));
return keccak256(buffer);
}
if (typeof data === 'object') {
const buffer = JSON.stringify(data);
return keccak256(buffer);
}
return keccak256(data);
}

const KECCAK256_UTF8 = {
method: keccak256Utf8,
method: keccak256Method,
name: SUPPORTED_VERIFICATION_METHOD_STRINGS.KECCAK256_UTF8,
sig: SUPPORTED_VERIFICATION_METHOD_HASHES.HASH_KECCAK256_UTF8,
};

const KECCAK256_BYTES = {
method: keccak256,
method: keccak256Method,
name: SUPPORTED_VERIFICATION_METHOD_STRINGS.KECCAK256_BYTES,
sig: SUPPORTED_VERIFICATION_METHOD_HASHES.HASH_KECCAK256_BYTES,
};

export const HASH_METHODS: {
[key: string]: {
method: Function;
method: (data: object | string | Uint8Array | null) => string;
name: SUPPORTED_VERIFICATION_METHOD_STRINGS;
sig: SUPPORTED_VERIFICATION_METHODS;
};
Expand Down Expand Up @@ -167,6 +179,7 @@ export const LSP6_DEFAULT_PERMISSIONS = {
DECRYPT : "0x0000000000000000000000000000000000000000000000000000000000100000",
SIGN : "0x0000000000000000000000000000000000000000000000000000000000200000",
EXECUTE_RELAY_CALL : "0x0000000000000000000000000000000000000000000000000000000000400000",
ERC4337_PERMISSION : "0x0000000000000000000000000000000000000000000000000000000000800000"
};

export const LSP6_ALL_PERMISSIONS =
Expand Down
Loading

0 comments on commit 1dd59bf

Please sign in to comment.