Skip to main content

LSP2ERC725YJSONSchema

decodeAssetUrl

decodeAssetUrl(assetUrlValue): Object

Decode a JSONURL value content.

Parameters

NameTypeDescription
assetUrlValueBytesLikeThe encoded value as { "valueContent": "ASSETURL" }.

Returns

Object

{
// The hash digest of the function used to hash the JSON file.
"hashFunction": "string"
// the hashed bytes value of the JSON file.
"json": "string"
// The URL where the JSON file is hosted.
"url": "string"
}
NameType
hashstring
hashFunctionstring
urlstring

Since

v0.0.1

Throws

When assetUrlValue his composed of less than 36 bytes.

See

https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md

Example

decodeAssetUrl("0x6f357c6a2a04850096912391bbb0966a624519e8f5d797df2a2c47425e892c25e00c053568747470733a2f2f676f6f676c652e636f6d2f") =>
{
hashFunction: "0x6f357c6a",
hash: "0x2a04850096912391bbb0966a624519e8f5d797df2a2c47425e892c25e00c0535",
url: "https://google.com/"
}

Defined in

LSP2ERC725YJSONSchema/decodeAssetUrl/decodeAssetUrl.ts:35


decodeJsonUrl

decodeJsonUrl(jsonUrlValue): Object

Decode a JSONURL value content.

Parameters

NameTypeDescription
jsonUrlValueBytesLikeThe encoded value as { "valueContent": "JSONURL" }.

Returns

Object

{
// The hash digest of the function used to hash the JSON file.
"hashFunction": "string"
// the hashed bytes value of the JSON file.
"json": "string"
// The URL where the JSON file is hosted.
"url": "string"
}
NameType
hashstring
hashFunctionstring
urlstring

Since

v0.0.1

Throws

When jsonUrlValue his composed of less than 36 bytes.

See

https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md

Example

decodeJsonUrl("0x6f357c6a4dade694d7dd4081f46073e99ce898a9b53cf6988452904de7db5cc704a4184968747470733a2f2f676f6f676c652e636f6d2f") =>
{
hashFunction: "0x6f357c6a",
hash: "0x4dade694d7dd4081f46073e99ce898a9b53cf6988452904de7db5cc704a41849",
url: "https://google.com/"
}

Defined in

LSP2ERC725YJSONSchema/decodeJsonUrl/decodeJsonUrl.ts:35


encodeAssetUrl

encodeAssetUrl(hashFunction, assetBytes, url): string

Generate a ASSETURL value content.

Parameters

NameTypeDescription
hashFunctionstringThe function used to hash the JSON file.
assetBytesstringBytes value of the JSON file.
urlstringThe URL where the JSON file is hosted.

Returns

string

The encoded value as an ASSETURL.

Since

v0.0.1

See

https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md

Example

encodeAssetUrl(
"keccak256(utf8)",
"{\"name\":\"USDStablecoin\",\"description\":\"Some random description about the token USD Stablecoin\"}",
"https://google.com/"
) => "0x6f357c6a2a04850096912391bbb0966a624519e8f5d797df2a2c47425e892c25e00c053568747470733a2f2f676f6f676c652e636f6d2f"

Defined in

LSP2ERC725YJSONSchema/encodeAssetUrl/encodeAssetUrl.ts:25


encodeJsonUrl

encodeJsonUrl(hashFunction, json, url): string

Encode a JSONURL value content.

Parameters

NameTypeDescription
hashFunctionstringThe function used to hash the JSON file.
jsonstringBytes value of the JSON file.
urlstringThe URL where the JSON file is hosted.

Returns

string

The encoded value as an JSONURL.

Since

v0.0.1

See

https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md

Example

encodeJsonUrl(
"keccak256(utf8)",
"{\"name\":\"Tom\",\"description\":\"Some random description about Tom\"}",
"https://google.com/"
) => "0x6f357c6a4dade694d7dd4081f46073e99ce898a9b53cf6988452904de7db5cc704a4184968747470733a2f2f676f6f676c652e636f6d2f"

Defined in

LSP2ERC725YJSONSchema/encodeJsonUrl/encodeJsonUrl.ts:25


generateArrayElementKeyAtIndex

generateArrayElementKeyAtIndex(arrayKey, index): string

Generates a data key of { "keyType": "Array" } at a specific index. arrayKey can have the following values:

  1. An array data key, 32 bytes hex value.
  2. An array data key name of type dataKeyName[] that will be used to generate an array data key using generateArrayKey(arrayKey).

Parameters

NameTypeDescription
arrayKeystringThe Array data key from which to generate the Array data key at a specific index.
indexnumberThe index number in the arrayKey.

Returns

string

The generated bytes32 data key of key type Array at a specific index.

Since

v0.0.1

See

https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md

Example

generateSingletonKey(arrayDataKeyName, index) => `<bytes16(keccak256(arrayDataKeyName))>:<bytes16(index)>`
generateSingletonKey(arrayDataKey, index) => `<bytes16(arrayDataKey)>:<bytes16(index)>`

Defined in

LSP2ERC725YJSONSchema/generateArrayElementKeyAtIndex/generateArrayElementKeyAtIndex.ts:24


generateArrayKey

generateArrayKey(arrayKeyName): string

Generates a data key of { "keyType": "Array" } by hashing arrayKeyName.

Parameters

NameTypeDescription
arrayKeyNamestringThe string that will be used to generate a data key of key type Array.

Returns

string

The generated bytes32 data key of key type Array.

Since

v0.0.1

Throws

keyName has less than 2 characters.

Throws

keyName does not include square brackets "[]" at the end of the string.

See

https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md

Example

generateArrayKey("RandomArrayDataKey[]") => keccak256("RandomArrayDataKey[]") = "0x6e9974ec39571e80dcc2ab1fac99097b03bb4617b071cd519a23d38f88f28ffb"

Defined in

LSP2ERC725YJSONSchema/generateArrayKey/generateArrayKey.ts:22


generateMappingKey

generateMappingKey(firstPart, lastPart): string

Generates a data key of { "keyType": "Mapping" } that map firstPart to lastPart.

firstPart can have the following values:

  1. A 10 bytes hex value.
  2. A hex value that will be hashed (first 10 bytes will be used).
  3. A UTF8 string that will be hashed (first 10 bytes will be used).

lastPart can have the following values:

  1. An address.
  2. A 20 bytes hex value.
  3. A hex value that will be hashed (first 20 bytes will be used).
  4. A UTF8 string that will be hashed (first 20 bytes will be used).

Parameters

NameTypeDescription
firstPartBytesLikeThe word to retrieve the first 10 bytes of its hash.
lastPartBytesLikeThe word to retrieve the first 10 bytes of its hash.

Returns

string

The generated bytes32 data key of key type Mapping that map firstPart to a specific lastPart.

Since

v0.0.1

See

https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md

Example

generateMappingKey(firstWord, lastWord) =>`<bytes10(keccak256(firstWord))>:<0000>:<bytes20(keccak256(lastWord))>`

generateMappingKey(firstWord, bytes20value) =>`<bytes10(keccak256(firstWord))>:<0000>:<bytes20value>`

generateMappingKey(bytes10Value, lastWord) =>`<bytes10Value>:<0000>:<bytes20(keccak256(lastWord))>`

generateMappingKey(bytes10Value, bytes20value) =>`<bytes10Value>:<0000>:<bytes20value>`

Defined in

LSP2ERC725YJSONSchema/generateMappingKey/generateMappingKey.ts:37


generateMappingWithGroupingKey

generateMappingWithGroupingKey(firstPart, middlePart, lastPart): string

Generates a data key of { "keyType": "MappingWithGrouping" } that map firstPart to middlePart and to lastPart.

firstPart can have the following values:

  1. A 6 bytes hex value.
  2. A hex value that will be hashed (first 6 bytes will be used).
  3. A UTF8 string that will be hashed (first 6 bytes will be used).

middlePart can have the following values:

  1. A 4 bytes hex value.
  2. A hex value that will be hashed (first 4 bytes will be used).
  3. A UTF8 string that will be hashed (first 4 bytes will be used).

lastPart can have the following values:

  1. An address.
  2. A 20 bytes hex value.
  3. A hex value that will be hashed (first 20 bytes will be used).
  4. A UTF8 string that will be hashed (first 20 bytes will be used).

Parameters

NameTypeDescription
firstPartBytesLikeThe word to retrieve the first 6 bytes of its hash.
middlePartBytesLikeThe word to retrieve the first 4 bytes of its hash.
lastPartBytesLikeThe word to retrieve the first 20 bytes of its hash.

Returns

string

The generated bytes32 data key of key type MappingWithGrouping that map a firstWord to a secondWord to a specific address addr.

Since

v0.0.1

See

https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md

Example

generateMappingWithGroupingKey(firstWord, middleWord, lastWord) => `<bytes6(keccak256(firstWord))>:<bytes4(keccak256(middleWord))>:<0000>:<bytes20(keccak256(lastWord))>`

generateMappingWithGroupingKey(firstWord, middleWord, bytes20Value) => `<bytes6(keccak256(firstWord))>:<bytes4(keccak256(middleWord))>:<0000>:<bytes20Value>`

generateMappingWithGroupingKey(firstWord, bytes4Value, lastWord) => `<bytes6(keccak256(firstWord))>:<bytes4Value>:<0000>:<bytes20(keccak256(lastWord))>`

generateMappingWithGroupingKey(firstWord, bytes4Value, bytes20Value) => `<bytes6(keccak256(firstWord))>:<bytes4Value>:<0000>:<bytes20Value>`

generateMappingWithGroupingKey(bytes6Value, middleWord, lastWord) => `<bytes6Value>:<bytes4(keccak256(middleWord))>:<0000>:<bytes20(keccak256(lastWord))>`

generateMappingWithGroupingKey(bytes6Value, middleWord, bytes20Value) => `<bytes6Value>:<bytes4(keccak256(middleWord))>:<0000>:<bytes20Value>`

generateMappingWithGroupingKey(bytes6Value, bytes4Value, lastWord) => `<bytes6Value>:<bytes4Value>:<0000>:<bytes20(keccak256(lastWord))>`

generateMappingWithGroupingKey(bytes6Value, bytes4Value, bytes20Value) => `<bytes6Value>:<bytes4Value>:<0000>:<bytes20Value>`

Defined in

LSP2ERC725YJSONSchema/generateMappingWithGroupingKey/generateMappingWithGroupingKey.ts:51


generateSingletonKey

generateSingletonKey(keyName): string

Generates a data key of { "keyType": "Singleton" } by hashing the string keyName.

Parameters

NameTypeDescription
keyNamestringThe string to hash to generate a Singleton data key.

Returns

string

The generated bytes32 data key of key type Singleton.

Since

v0.0.1

See

https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md

Example

generateSingletonKey("RandomDataKey") => keccak256("RandomKeyName") = "0xb0c92ac98a2a422f33a3e130e3fa6e922195f0a0a99199963814012351f906cb"

Defined in

LSP2ERC725YJSONSchema/generateSingletonKey/generateSingletonKey.ts:19


isCompactBytesArray

isCompactBytesArray(compactBytesArray): boolean

Verify if data is a valid array of value encoded as a CompactBytesArray according to the LSP2 CompactBytesArray valueType specification.

Parameters

NameTypeDescription
compactBytesArrayBytesLikeThe bytes value to verify.

Returns

boolean

true if the data is correctly encoded CompactBytesArray, false otherwise.

Since

v0.0.1

See

https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md

Example

isCompactBytesArray("0x0002cafe000abeefdeadbeef0000cafe") => true
isCompactBytesArray("0x0002cafecafe000abeefdeadbeef0000cafe") => false
isCompactBytesArray("0x0002") => false

Defined in

LSP2ERC725YJSONSchema/isCompactBytesArray/isCompactBytesArray.ts:21


isValidArrayLengthValue

isValidArrayLengthValue(arrayLength): boolean

Validates if the bytes arrayLength are exactly 16 bytes long, and are of the exact size of an LSP2 Array length value

Parameters

NameTypeDescription
arrayLengthBytesLikePlain bytes that should be validated.

Returns

boolean

true if the value is 16 bytes long, false otherwise.

Since

v0.0.1

See

https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md

Example

isValidArrayLengthValue("0x00000000000000000000000000000001") => true
isValidArrayLengthValue("0x00000000000000000000000000000a3b") => true
isValidArrayLengthValue("0x000000000000000000000000004a") => false
isValidArrayLengthValue("0x0000000000000000000000000000000000f60a") => false

Defined in

LSP2ERC725YJSONSchema/isValidArrayLengthValue/isValidArrayLengthValue.ts:22


removeElementFromArrayAndMap

removeElementFromArrayAndMap(erc725YContract, arrayKey, newArrayLength, removedElementIndexKey, removedElementIndex, removedElementMapKey): Promise<{ dataKeys: BytesLike[] ; dataValues: BytesLike[] }>

Generates Data Key/Value pairs for removing an element from an LSP2 Array and a mapping Data Key.

Parameters

NameTypeDescription
erc725YContractUniversalProfileThe ERC725Y contract.
arrayKeyBytesLikeThe Data Key of Key Type Array.
newArrayLengthnumberThe new Array Length for the arrayKey.
removedElementIndexKeyBytesLikeThe Data Key of Key Type Array Index for the removed element.
removedElementIndexnumberthe index of the removed element.
removedElementMapKeyBytesLikeThe Data Key of a mapping to be removed.

Returns

Promise<{ dataKeys: BytesLike[] ; dataValues: BytesLike[] }>

A set of data keys & data values that can be used to update an array and map in ERC725Y storage.

Since

v0.0.1

See

https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md

Example

removeLastElementFromArrayAndMap(...) => { dataKeys: BytesLike[], dataValues: BytesLike[] }

Defined in

LSP2ERC725YJSONSchema/removeElementFromArrayAndMap/removeElementFromArrayAndMap.ts:32


removeLastElementFromArrayAndMap

removeLastElementFromArrayAndMap(arrayKey, newArrayLength, removedElementIndexKey, removedElementMapKey): Object

Generates Data Key/Value pairs for removing the last element from an LSP2 Array and a mapping Data Key.

Parameters

NameTypeDescription
arrayKeyBytesLikeThe Data Key of Key Type Array.
newArrayLengthnumberThe new Array Length for the arrayKey.
removedElementIndexKeyBytesLikeThe Data Key of Key Type Array Index for the removed element.
removedElementMapKeyBytesLikeThe Data Key of a mapping to be removed.

Returns

Object

A set of data keys & data values that can be used to update an array and map in ERC725Y storage.

NameType
dataKeysBytesLike[]
dataValuesBytesLike[]

Since

v0.0.1

See

https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md

Example

removeLastElementFromArrayAndMap(...) => { dataKeys: BytesLike[], dataValues: BytesLike[] }

Defined in

LSP2ERC725YJSONSchema/removeLastElementFromArrayAndMap/removeLastElementFromArrayAndMap.ts:22