General
Methods that apply for both Bitcoin L1 and Bison ZK-Rollup
Methods
requestAccounts
zky.requestAccounts()
Connect the current account.
Parameters
None
Returns
Promise
- string[]
: Address of current account.
Example
try {
let accounts = await window.zky.requestAccounts();
console.log('connect success', accounts);
} catch (e) {
console.log('connect failed');
}
> connect success ['tb1pq53qftc428auwq7k08dtme6e7anwewslvfszp2exey8zkylkkf2qx24rlm']
getAccounts
Get address of current account.
Parameters
None
Returns
Promise
- string[]
: Address of current account.
Example
try {
let res = await window.zky.getAccounts();
console.log(res);
} catch (e) {
console.log(e);
}
> ['tb1pq53qftc428auwq7k08dtme6e7anwewslvfszp2exey8zkylkkf2qx24rlm']
getNetwork
Get current network.
Parameters
None
Returns
Promise
- string[]
: the network, livenet
and testnet
.
Example
try {
let res = await window.zky.getNetwork();
console.log(res);
} catch (e) {
console.log(e);
}
> 0
switchNetwork (Coming soon)
zky.switchNetwork(network)
Switch current network.
Parameters
network
- string
: the network. livenest
and testnet
Returns
None
Example
try {
let res = await window.zky.switchNetwork("livenet");
console.log(res);
} catch (e) {
console.log(e);
}
> 0
getPublicKey
Get publicKey of current account.
Parameters
None
Returns
Promise
- string
: publicKey.
Example
try {
let res = await window.zky.getPublicKey();
console.log(res)
} catch (e) {
console.log(e);
}
> 03cbaedc26f03fd3ba02fc936f338e980c9e2172c5e23128877ed46827e935296f
signMessage
zky.signMessage(msg, type)
Sign message.
Parameters
msg
- string
: a string to sign.
type
- string
: (Optional) "ecdsa" | "bip322-simple". default is "ecdsa".
Returns
Promise
- string
: the signature.
Example
// sign by ecdsa
try {
let res = await window.zky.signMessage("abcdefghijk123456789");
console.log(res)
} catch (e) {
console.log(e);
}
> G+LrYa7T5dUMDgQduAErw+i6ebK4GqTXYVWIDM+snYk7Yc6LdPitmaqM6j+iJOeID1CsMXOJFpVopvPiHBdulkE=
// verify by ecdsa
import { verifyMessage } from "@unisat/wallet-utils";
const pubkey = "026887958bcc4cb6f8c04ea49260f0d10e312c41baf485252953b14724db552aac";
const message = "abcdefghijk123456789";
const signature = "G+LrYa7T5dUMDgQduAErw+i6ebK4GqTXYVWIDM+snYk7Yc6LdPitmaqM6j+iJOeID1CsMXOJFpVopvPiHBdulkE=";
const result = verifyMessage(pubkey,message,signature);
console.log(result);
> true
// sign by bip322-simple
try {
let res = await window.zky.signMessage("abcdefghijk123456789","bip322-simple");
console.log(res)
} catch (e) {
console.log(e);
}
> AkcwRAIgeHUcjr0jODaR7GMM8cenWnIj0MYdGmmrpGyMoryNSkgCICzVXWrLIKKp5cFtaCTErY7FGNXTFe6kuEofl4G+Vi5wASECaIeVi8xMtvjATqSSYPDRDjEsQbr0hSUpU7FHJNtVKqw=
signMultipleMessages
zky.signMultipleMessages(messages, type)
Sign multiple messages at once.
Parameters
messages
- string[]
: an array of strings to sign.
type
- string
: (Optional) "ecdsa" | "bip322-simple". default is "ecdsa".
Returns
Promise
- string[]
: the array of signatures (one for each message).
Example
// sign by bip322-simple
try {
let res = await window.zky.signMessage(["hello", "world!"],"bip322-simple");
console.log(res)
} catch (e) {
console.log(e);
}
> ['AUBC+0A7Y2fFfN6N9cXMuJnrNCsiQPgzqaZeteaohPZKbcRnCjibwC5K+VsqmaF0a5Xj57AX+koDt4NI2Sz36hqG', 'AUAGCSiOY+Hla0OdkSG7tUb3czwwF8QY2e6y2kRGOscwf4rbG6PVunVuLxk9GwIwXtUOnaV+t74o8/yQwWttXZNm']
Events
accountsChanged
zky.on('accountsChanged', handler: (accounts: Array<string>) => void);
zky.removeListener('accountsChanged', handler: (accounts: Array<string>) => void);
The accountsChanged
will be emitted whenever the user's exposed account address changes.
networkChanged
zky.on('networkChanged', handler: (network: string) => void);
zky.removeListener('networkChanged', handler: (network: string) => void);
The networkChanged
will be emitted whenever the user's network changes.
Last updated