-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add signing and verifying message docs
- Loading branch information
Showing
20 changed files
with
536 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
book | ||
.DS_Store | ||
.idea | ||
*.sln | ||
*.nupkg |
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,50 @@ | ||
using Breez.Sdk; | ||
|
||
public class MessagesSnippets | ||
{ | ||
public void SignMessage(BlockingBreezServices sdk) | ||
{ | ||
// ANCHOR: sign-message | ||
var message = "<message to sign>"; | ||
try | ||
{ | ||
var signMessageResponse = sdk.SignMessage(new SignMessageRequest(message)); | ||
|
||
// Get the node info for your pubkey | ||
var info = sdk.NodeInfo(); | ||
|
||
var signature = signMessageResponse?.signature; | ||
var pubkey = info?.id; | ||
|
||
Console.WriteLine($"Pubkey: {pubkey}"); | ||
Console.WriteLine($"Signature: {signature}"); | ||
} | ||
catch (Exception) | ||
{ | ||
// Handle error | ||
} | ||
// ANCHOR_END: sign-message | ||
} | ||
|
||
public void CheckMessage(BlockingBreezServices sdk) | ||
{ | ||
// ANCHOR: check-message | ||
var message = "<message>"; | ||
var pubkey = "<pubkey of signer>"; | ||
var signature = "<message signature>"; | ||
try | ||
{ | ||
var checkMessageRequest = new CheckMessageRequest(message, pubkey, signature); | ||
var checkMessageResponse = sdk.CheckMessage(checkMessageRequest); | ||
|
||
var isValid = checkMessageResponse?.isValid; | ||
|
||
Console.WriteLine($"Signature valid: {isValid}"); | ||
} | ||
catch (Exception) | ||
{ | ||
// Handle error | ||
} | ||
// ANCHOR_END: check-message | ||
} | ||
} |
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,37 @@ | ||
import 'package:dart_snippets/sdk_instance.dart'; | ||
import 'package:breez_sdk/bridge_generated.dart'; | ||
|
||
Future<SignMessageResponse> signMessage() async { | ||
// ANCHOR: sign-message | ||
SignMessageResponse signMessageResponse = await breezSDK.signMessage( | ||
req: SignMessageRequest(message: "<message to sign>"), | ||
); | ||
|
||
// Get the node info for your pubkey | ||
NodeState? info = await breezSDK.nodeInfo(); | ||
|
||
String signature = signMessageResponse.signature; | ||
String? pubkey = info?.id; | ||
|
||
print("Pubkey: $pubkey"); | ||
print("Signature: $signature"); | ||
// ANCHOR_END: sign-message | ||
return signMessageResponse; | ||
} | ||
|
||
Future<CheckMessageResponse> checkMessage() async { | ||
// ANCHOR: check-message | ||
CheckMessageResponse checkMessageResponse = await breezSDK.checkMessage( | ||
req: CheckMessageRequest( | ||
message: "<message>", | ||
pubkey: "<pubkey of signer>", | ||
signature: "<message signature>" | ||
), | ||
); | ||
|
||
bool isValid = checkMessageResponse.isValid; | ||
|
||
print("Signature valid: $isValid"); | ||
// ANCHOR_END: check-message | ||
return checkMessageResponse; | ||
} |
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,60 @@ | ||
package example | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/breez/breez-sdk-go/breez_sdk" | ||
) | ||
|
||
func SignMessage() { | ||
// ANCHOR: sign-message | ||
message := "<message to sign>" | ||
|
||
signMessageRequest := breez_sdk.SignMessageRequest{ | ||
Message: message, | ||
} | ||
|
||
signMessageResponse, err := sdk.SignMessage(signMessageRequest) | ||
if err != nil { | ||
log.Printf("Error: %#v", err) | ||
return | ||
} | ||
|
||
// Get the node info for your pubkey | ||
info, err := sdk.NodeInfo() | ||
if err != nil { | ||
log.Printf("Error: %#v", err) | ||
return | ||
} | ||
|
||
signature := signMessageResponse.Signature | ||
pubkey := info.Id | ||
|
||
log.Printf("Pubkey: %v", pubkey) | ||
log.Printf("Signature: %v", signature) | ||
// ANCHOR_END: sign-message | ||
} | ||
|
||
func CheckMessage() { | ||
// ANCHOR: check-message | ||
message := "<message>" | ||
pubkey := "<pubkey of signer>" | ||
signature := "<message signature>" | ||
|
||
checkMessageRequest := breez_sdk.CheckMessageRequest{ | ||
Message: message, | ||
Pubkey: pubkey, | ||
Signature: signature, | ||
} | ||
|
||
checkMessageResponse, err := sdk.CheckMessage(checkMessageRequest) | ||
if err != nil { | ||
log.Printf("Error: %#v", err) | ||
return | ||
} | ||
|
||
isValid := checkMessageResponse.IsValid | ||
|
||
log.Printf("Signature valid: %v", isValid) | ||
// ANCHOR_END: check-message | ||
} |
44 changes: 44 additions & 0 deletions
44
snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/Messages.kt
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,44 @@ | ||
package com.example.kotlinmpplib | ||
|
||
import breez_sdk.* | ||
|
||
class Messages { | ||
fun signMessage(sdk: BlockingBreezServices) { | ||
// ANCHOR: sign-message | ||
val message = "<message to sign>" | ||
try { | ||
val signMessageResponse = sdk.signMessage(SignMessageRequest(message)) | ||
|
||
// Get the node info for your pubkey | ||
val info = sdk.nodeInfo() | ||
|
||
val signature = signMessageResponse?.signature | ||
val pubkey = info?.id | ||
|
||
// Log.v("Breez", "Pubkey: ${pubkey}") | ||
// Log.v("Breez", "Signature: ${signature}") | ||
} catch (e: Exception) { | ||
// handle error | ||
} | ||
// ANCHOR_END: sign-message | ||
} | ||
|
||
fun checkMessage(sdk: BlockingBreezServices) { | ||
// ANCHOR: check-message | ||
val message = "<message>" | ||
val pubkey = "<pubkey of signer>" | ||
val signature = "<message signature>" | ||
try { | ||
val checkMessageRequest = CheckMessageRequest(message, pubkey, signature) | ||
val checkMessageResponse = sdk.checkMessage(checkMessageRequest) | ||
|
||
val isValid = checkMessageResponse?.isValid | ||
|
||
// Log.v("Breez", "Signature valid: ${isValid}") | ||
} catch (e: Exception) { | ||
// handle error | ||
} | ||
// ANCHOR_END: check-message | ||
} | ||
|
||
} |
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,39 @@ | ||
import logging | ||
import breez_sdk | ||
|
||
|
||
def sign_message(sdk_services): | ||
# ANCHOR: sign-message | ||
message = "<message to sign>" | ||
try: | ||
sign_message_response = sdk_services.sign_message(breez_sdk.SignMessageRequest(message)) | ||
|
||
# Get the node info for your pubkey | ||
info = sdk_services.node_info() | ||
|
||
signature = sign_message_response.signature | ||
pubkey = info.id | ||
|
||
logging.debug(f"Pubkey: {pubkey}") | ||
logging.debug(f"Signature: {signature}") | ||
except Exception as error: | ||
logging.error(error) | ||
raise | ||
# ANCHOR_END: sign-message | ||
|
||
def check_message(sdk_services): | ||
# ANCHOR: check-message | ||
message = "<message>" | ||
pubkey = "<pubkey of signer>" | ||
signature = "<message signature>" | ||
try: | ||
check_message_request = breez_sdk.CheckMessageRequest(message, pubkey, signature) | ||
check_message_response = sdk_services.check_message(check_message_request) | ||
|
||
is_valid = check_message_response.is_valid | ||
|
||
logging.debug(f"Signature valid: {is_valid}") | ||
except Exception as error: | ||
logging.error(error) | ||
raise | ||
# ANCHOR_END: check-message |
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,35 @@ | ||
import { | ||
checkMessage, | ||
nodeInfo, | ||
signMessage | ||
} from '@breeztech/react-native-breez-sdk' | ||
|
||
const exampleSignMessage = async () => { | ||
// ANCHOR: sign-message | ||
const signMessageResponse = await signMessage({ | ||
message: '<message to sign>' | ||
}) | ||
|
||
// Get the node info for your pubkey | ||
const info = await nodeInfo() | ||
|
||
const signature = signMessageResponse.signature | ||
const pubkey = info.id | ||
|
||
console.log(`Pubkey: ${pubkey}`) | ||
console.log(`Signature: ${signature}`) | ||
// ANCHOR_END: sign-message | ||
} | ||
|
||
const exampleCheckMessage = async () => { | ||
// ANCHOR: check-message | ||
const checkMessageResponse = await checkMessage({ | ||
message: '<message>', | ||
pubkey: '<pubkey of signer>', | ||
signature: '<message signature>' | ||
}) | ||
const isValid = checkMessageResponse.isValid | ||
|
||
console.log(`Signature valid: ${isValid}`) | ||
// ANCHOR_END: check-message | ||
} |
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
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
Oops, something went wrong.