Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bsx-engineering/319dab1ea0c9f063c6fde9fd9d9a7787 to your computer and use it in GitHub Desktop.
Save bsx-engineering/319dab1ea0c9f063c6fde9fd9d9a7787 to your computer and use it in GitHub Desktop.
import Safe, { SigningMethod, buildContractSignature } from '@safe-global/protocol-kit'
const MESSAGE = {
types: {
EIP712Domain: [
{
name: 'name',
type: 'string'
},
{
name: 'version',
type: 'string'
},
{
name: 'chainId',
type: 'uint256'
},
{
name: 'verifyingContract',
type: 'address'
}
],
Register: [
{
name: 'key',
type: 'address'
},
{
name: 'message',
type: 'string'
},
{
name: 'nonce',
type: 'uint64'
}
]
},
primaryType: 'Register',
domain: {
name: 'BSX Testnet',
version: '1',
chainId: Number(84532),
verifyingContract: '0x6d6F70C0778C57664E32bA6b65b637cBc0C41F09'
},
message: {
key: '0x6263F97AE4360c5E057e42b36ff8e0Ee554673e6',
message:
'Please sign in with your wallet to access bsx.exchange. You are signing in on 1722929625000000000. This message is exclusively signed with bsx.exchange for security.',
nonce: '1722929625000000000'
}
}
interface Config {
RPC_URL: string
OWNER1_PRIVATE_KEY: string
OWNER2_PRIVATE_KEY: string
SAFE_2_2_ADDRESS: string
}
const config: Config = {
RPC_URL: 'https://sepolia.base.org',
OWNER1_PRIVATE_KEY: 'b2772045811cf64a001aedbd4debf0a1787fbf507e1a284a4df9100a6374935d',
OWNER2_PRIVATE_KEY: '05600ca16954938238344fe571b5ee0afd6dce28d4759efd2dfb1f1628483c9b',
SAFE_2_2_ADDRESS: '0xF6CDA5B4432D66267941bA9eb1Bd3E285B3aE13e'
}
async function main() {
let protocolKit = await Safe.init({
provider: config.RPC_URL,
safeAddress: config.SAFE_2_2_ADDRESS
})
// Create a new message object
let messageSafe2_2 = protocolKit.createMessage(MESSAGE)
// Connect OWNER1_ADDRESS
protocolKit = await protocolKit.connect({
signer: config.OWNER1_PRIVATE_KEY
})
// Sign the messageSafe2_2 with OWNER1_ADDRESS
// After this, the messageSafe2_2 contains the signature from OWNER1_ADDRESS
messageSafe2_2 = await protocolKit.signMessage(
messageSafe2_2,
SigningMethod.SAFE_SIGNATURE,
config.SAFE_2_2_ADDRESS
)
// Connect OWNER2_ADDRESS
protocolKit = await protocolKit.connect({
signer: config.OWNER2_PRIVATE_KEY
})
// Sign the messageSafe2_2 with OWNER2_ADDRESS
// After this, the messageSafe2_2 contains the signature from OWNER2_ADDRESS
messageSafe2_2 = await protocolKit.signMessage(
messageSafe2_2,
SigningMethod.SAFE_SIGNATURE,
config.SAFE_2_2_ADDRESS
)
// Build the contract signature of SAFE_2_2_ADDRESS
const signatureSafe2_2 = await buildContractSignature(
Array.from(messageSafe2_2.signatures.values()),
config.SAFE_2_2_ADDRESS
)
// Add the signatureSafe2_2 to safeMessage
// After this, the safeMessage contains the signature from OWNER_1_ADDRESS, OWNER_2_ADDRESS
messageSafe2_2.addSignature(signatureSafe2_2)
console.log('Signature: ', messageSafe2_2.encodedSignatures())
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment