-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '95-pubsub-senderId' into 'dev'
Resolve "Add sign/verify to pubsub due to lack of senderID" Closes #95 See merge request ergo/rosen-bridge/rosenet!59
- Loading branch information
Showing
10 changed files
with
129 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@rosen-bridge/rosenet-node': minor | ||
'@rosen-bridge/rosenet-utils': minor | ||
--- | ||
|
||
Add sign/verify messages in pubub protocol and add from field to subscribe handler |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,30 @@ | ||
import { unmarshalPrivateKey, unmarshalPublicKey } from '@libp2p/crypto/keys'; | ||
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; | ||
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'; | ||
|
||
/** | ||
* sign data using provided private key | ||
* @param privKeyBytes | ||
* @param data | ||
*/ | ||
const sign = async (privKeyBytes: Uint8Array, data: string) => { | ||
const privKey = await unmarshalPrivateKey(privKeyBytes); | ||
const signature = await privKey.sign(uint8ArrayFromString(data, 'utf-8')); | ||
return uint8ArrayToString(signature, 'hex'); | ||
}; | ||
|
||
/** | ||
* verify data using publicKey and provided signature | ||
* @param pubKeyBytes | ||
* @param data | ||
* @param signature | ||
*/ | ||
const verify = async (pubKeyBytes: string, data: string, signature: string) => { | ||
const pubKey = unmarshalPublicKey(Buffer.from(pubKeyBytes, 'hex')); | ||
return pubKey.verify( | ||
uint8ArrayFromString(data, 'utf-8'), | ||
uint8ArrayFromString(signature, 'hex'), | ||
); | ||
}; | ||
|
||
export default { sign, verify }; |
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,23 @@ | ||
import { unmarshalPublicKey } from '@libp2p/crypto/keys'; | ||
import { createFromPubKey } from '@libp2p/peer-id-factory'; | ||
|
||
/** | ||
* convert a public key string to a PublicKey object | ||
* @param publicKey hex encoded public key in any of rsa, ed25519, or | ||
* secp256k1 formats | ||
*/ | ||
const unmarshalPublicKeyString = (publicKey: string) => | ||
unmarshalPublicKey(Buffer.from(publicKey, 'hex')); | ||
|
||
/** | ||
* generate a peer id from a public key | ||
* | ||
* @param publicKey hex encoded public key in any of rsa, ed25519, or | ||
* secp256k1 formats | ||
*/ | ||
const peerIdFromPublicKey = async (publicKey: string) => { | ||
const publicKeyObj = unmarshalPublicKeyString(publicKey); | ||
return await createFromPubKey(publicKeyObj); | ||
}; | ||
|
||
export default peerIdFromPublicKey; |
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