Skip to content

Commit

Permalink
fix: Refactoring decoding output class and adding decoding valid CIDv…
Browse files Browse the repository at this point in the history
…1 test.
  • Loading branch information
LuchoTurtle committed Jun 23, 2023
1 parent f1a5ef9 commit af3eaa4
Show file tree
Hide file tree
Showing 6 changed files with 575 additions and 548 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ we would get access to the following info.
```dart
{
"code": 0x12,
"length": 32,
"digest": [165, 145, 166, 212, 11, 244, 32, 64, 74, 1, 23, 51, 207, 183, 177, 144, 214, 44, 101, 191, 11, 205, 163, 43, 87, 178, 119, 217, 173, 159, 20, 110],
"name": "sha2-256",
"size": 32,
"digest": [165, 145, 166, 212, 11, 244, 32, 64, 74, 1, 23, 51, 207, 183, 177, 144, 214, 44, 101, 191, 11, 205, 163, 43, 87, 178, 119, 217, 173, 159, 20, 110],
}
```

Expand Down
5 changes: 3 additions & 2 deletions lib/src/multihash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Multihash {
}

// Function convention info
Codec hashInfo = codecTable.firstWhere((obj) => obj.name == hashType);
MultiCodec hashInfo = codecTable.firstWhere((obj) => obj.name == hashType);

// Check if length of digest is correctly defined.
length ??= digest.length;
Expand All @@ -34,6 +34,7 @@ class Multihash {
}

/// Decodes an array of bytes into a multihash object.
/// See https://cid.ipfs.tech/#bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi to better understand what each varint means.
static MultihashInfo decode(Uint8List bytes) {
// Check if the array of bytes is long enough
// (has to have hash function type, length of digest and digest)
Expand Down Expand Up @@ -64,6 +65,6 @@ class Multihash {
// Fetch name of hash function type referring to the code
String hashName = codecTable.firstWhere((obj) => obj.code == decodedCode.res).name;

return MultihashInfo(code: decodedCode.res, length: decodedLen.res, name: hashName, digest: bytes);
return MultihashInfo(code: decodedCode.res, size: decodedLen.res, name: hashName, digest: bytes);
}
}
Loading

0 comments on commit af3eaa4

Please sign in to comment.