Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICRC-3 #128

Merged
merged 46 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
4b322bb
add icrc-3 draft
MarioDfinity Jul 11, 2023
9b44eb0
add requirements for Values representing Transactions
MarioDfinity Jul 11, 2023
4319f1a
Update standards/ICRC-3/README.md
MarioDfinity Jul 11, 2023
8dd28f1
Update standards/ICRC-3/README.md
MarioDfinity Jul 11, 2023
570a200
fix graph
MarioDfinity Jul 11, 2023
3cdbaac
add ICRC1 schemas examples
MarioDfinity Jul 11, 2023
01252e5
ICRC-2
MarioDfinity Jul 11, 2023
ebec6c7
move schemas for ICRC-1 and ICRC-2 to ICRC-3 README.md
MarioDfinity Jul 25, 2023
29f90e8
Update standards/ICRC-3/README.md
MarioDfinity Sep 19, 2023
e50331b
Update standards/ICRC-3/README.md
MarioDfinity Sep 19, 2023
bfa5ca3
Merge
MarioDfinity Nov 8, 2023
db51936
pseudocode for hashing values
bogwar Nov 8, 2023
9f6dc65
output for hashing an array test vector
bogwar Nov 14, 2023
d6fd4ae
Incorporated changes from 14th Nov 2023 working group
MarioDfinity Nov 27, 2023
0e4b103
add "the hash of the" for Nat and Int
MarioDfinity Nov 27, 2023
25f86b7
expected_allowance switched to Nat
MarioDfinity Nov 27, 2023
1199b1f
s/u64/Nat64/
MarioDfinity Nov 27, 2023
880e549
Update standards/ICRC-3/README.md
MarioDfinity Nov 27, 2023
1d42f10
Update standards/ICRC-3/README.md
MarioDfinity Nov 27, 2023
ef995e0
missing of
MarioDfinity Nov 27, 2023
4547854
why
MarioDfinity Nov 28, 2023
968fa14
examples
MarioDfinity Nov 28, 2023
a09e60a
add get_archives
MarioDfinity Nov 28, 2023
70aa2ee
Update standards/ICRC-3/README.md
MarioDfinity Nov 28, 2023
101b90c
Update standards/ICRC-3/README.md
MarioDfinity Nov 28, 2023
dd4b51a
add icrc3_get_archives to did file
MarioDfinity Nov 28, 2023
9cc6ce1
fix did file
MarioDfinity Nov 28, 2023
362a4d5
Update standards/ICRC-3/README.md
MarioDfinity Nov 28, 2023
1c96c87
Update standards/ICRC-3/README.md
MarioDfinity Nov 29, 2023
c1cfd5f
Update standards/ICRC-3/README.md
MarioDfinity Nov 29, 2023
2d53c86
tx.op schema for ICRC standards
MarioDfinity Nov 29, 2023
be22f71
block typee and supported blocks
MarioDfinity Mar 11, 2024
ab3e9aa
add icrc3_supported_block_types to did file
MarioDfinity Mar 11, 2024
2736d79
fix ICRC-2
MarioDfinity Mar 11, 2024
8977901
fix GetArchivesResult
MarioDfinity Mar 13, 2024
3c29c17
add missing ;
MarioDfinity Mar 13, 2024
d06826e
Update README.md
MarioDfinity Mar 15, 2024
8d80565
Update README.md
MarioDfinity Mar 15, 2024
1467044
use btype instead of type
MarioDfinity Mar 18, 2024
96245c6
fallsback -> falls back
MarioDfinity Mar 18, 2024
c2531e9
better description
MarioDfinity Mar 18, 2024
b74946e
use rfc5234
MarioDfinity Mar 18, 2024
be84cad
fix
MarioDfinity Mar 18, 2024
3a2d197
1xfer for icrc1_transfer
MarioDfinity Mar 19, 2024
4871a8c
Accepted
MarioDfinity Apr 2, 2024
65ed86d
Update ICRC-3.did
MarioDfinity Apr 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions standards/ICRC-3/HASHINGVALUES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
## Representation independent hashing

The following pseudocode specifies how to calculate the (representation independent) hash of an element of the Value type. Some test vectors to check compliance of an implementation with this specification follow.

```
type Value = variant {
Blob : blob,
Text : text,
Nat : nat,
Int : int,
Array : vec Value,
Map : vec (text, Value)
};

Function hash_value(value)
Initialize hasher as a new instance of SHA256

Match value with
Nat:
Return SHA256_hash(LEB128_encode(value))
Int:
Return SHA256_hash(SLEB128_encode(value))
Text:
Return SHA256_hash(UTF8_encode(value))
Blob:
Return SHA256_hash(value)
Array:
For each element in value
Update hasher with hash_value(element)
Return hasher.finalize()
Map:
Initialize hashes as empty list
For each (key, val) in value
Add (SHA256_hash(UTF8_encode(key)), hash_value(val)) to hashes
Sort hashes in lexicographical order
For each (key_hash, val_hash) in hashes
Update hasher with key_hash
Update hasher with val_hash
Return hasher.finalize()
Else:
Return error "unsupported value type"
End Function

Function LEB128_encode(nat_input)
Convert nat_input to LEB128 byte encoding
End Function

Function SLEB128_encode(integer_input)
Convert integer_input to SLEB128 byte encoding
End Function

Function UTF8_encode(text)
Convert text to UTF-8 byte array and return it
End Function

Function SHA256_hash(data)
Initialize a new SHA256 hasher
Update hasher with data
Return hasher.finalize()
End Function

```

## Test vectors


```ignorelang
input: Nat(42)
expected output: 684888c0ebb17f374298b65ee2807526c066094c701bcc7ebbe1c1095f494fc1
```

```ignorelang
input: Int(-42)
expected output: de5a6f78116eca62d7fc5ce159d23ae6b889b365a1739ad2cf36f925a140d0cc
```


```ignorelang
input: Text("Hello, World!"),
expected output: dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f
```

```ignorelang
input: Blob(b'\x01\x02\x03\x04')
expected output: 9f64a747e1b97f131fabb6b447296c9b6f0201e79fb3c5356e6c77e89b6a806a
```

```ignorelang
input: Array([Nat(3), Text("foo"), Blob(b'\x05\x06')])
expected output: 514a04011caa503990d446b7dec5d79e19c221ae607fb08b2848c67734d468d6
```

```ignorelang
input: Map([("from", Blob(b'\x00\xab\xcd\xef\x00\x12\x34\x00\x56\x78\x9a\x00\xbc\xde\xf0\x00\x01\x23\x45\x67\x89\x00\xab\xcd\xef\x01')),
("to", Blob(b'\x00\xab\x0d\xef\x00\x12\x34\x00\x56\x78\x9a\x00\xbc\xde\xf0\x00\x01\x23\x45\x67\x89\x00\xab\xcd\xef\x01')),
("amount", Nat(42)),
("created_at", Nat(1699218263)),
("memo", Nat(0))
])

expected output: c56ece650e1de4269c5bdeff7875949e3e2033f85b2d193c2ff4f7f78bdcfc75
```
56 changes: 56 additions & 0 deletions standards/ICRC-3/ICRC-3.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
type Value = variant {
Blob : blob;
Text : text;
Nat : nat; // do we need this or can we just use Int?
Int : int;
Array : vec Value;
Map : vec record { text; Value };
};

type GetArchivesArgs = record {
// The last archive seen by the client.
// The Ledger will return archives coming
// after this one if set, otherwise it
// will return the first archives.
from : opt principal;
};

type GetArchivesResult = vec {
// The id of the archive
canister_id : principal;

// The first block in the archive
start : nat;

// The last block in the archive
end : nat;
}
MarioDfinity marked this conversation as resolved.
Show resolved Hide resolved
MarioDfinity marked this conversation as resolved.
Show resolved Hide resolved

type GetBlocksArgs = vec record { start : nat; length : nat };
MarioDfinity marked this conversation as resolved.
Show resolved Hide resolved

type GetBlocksResult = record {
// Total number of blocks in the
// block log
log_length : nat;

blocks : vec record { id : nat; block: Value };

archived_blocks : vec record {
args : GetBlocksArgs;
callback : func (GetBlocksArgs) -> (GetBlocksResult) query;
};
};
MarioDfinity marked this conversation as resolved.
Show resolved Hide resolved

type DataCertificate = record {
// See https://internetcomputer.org/docs/current/references/ic-interface-spec#certification
certificate : blob;

// CBOR encoded hash_tree
hash_tree : blob;
};

service : {
icrc3_get_archives : (GetArchivesArgs) -> (GetArchivesResult) query;
icrc3_get_tip_certificate : () -> (opt DataCertificate) query;
icrc3_get_blocks : (GetBlocksArgs) -> (GetBlocksResult) query;
};
Loading
Loading