-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(WorkersTable): fix peerId format
- Loading branch information
Showing
4 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { base58btc } from 'multiformats/bases/base58' | ||
|
||
/** | ||
* Fluence peer ids encoding follows the libp2p spec: | ||
* https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md. | ||
* | ||
* - Peer PK is bytes (32 bytes for Ed25519) | ||
* - Peer PK is encoded with key type into protobuf (1 for Ed25519) | ||
* - Peer ID is encoded Peer PK hashed using multihash (identity hash) | ||
* - Peer ID text representation is Peer ID encoded with base58btc | ||
* | ||
* On chain Peer PK is stored as bytes32. | ||
* Off chain Peer ID text representation is used. | ||
*/ | ||
|
||
const PEER_BYTE58_PREFIX = new Uint8Array([ | ||
0, // identity hash | ||
36, // length of the following data in bytes | ||
8, // protobuf varint tag | ||
1, // varint value (1 for Ed25519 key type) | ||
18, // protobuf bytes tag | ||
32, // length of the following data in bytes (Peer PK) | ||
]) | ||
|
||
const BASE_58_PREFIX = 'z' | ||
|
||
export function peerIdContractHexToBase58(peerIdHex: string) { | ||
return base58btc | ||
.encode( | ||
Buffer.concat([ | ||
PEER_BYTE58_PREFIX, | ||
Buffer.from(peerIdHex.slice(2), 'hex'), | ||
]), | ||
) | ||
.slice(BASE_58_PREFIX.length) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters