@reclaimprotocol/crypto-sdk
v1.4.0
Published
Crypto SDK to handle all crypto related operations for reclaim protocol
Downloads
118
Maintainers
Keywords
Readme
Reclaim crypto SDK
Crypto SDK Provides common functions for encrypting, decrypting, signing & verifying data used in Reclaim protocol. It's also used for generating & verifying auth tokens used in Reclaim backend
Setup
- Run
npm i
Creating an account
- Generate a new wallet by calling
const wallet = Wallet.createRandom()
Authentication
- Create an auth token by calling
await generateAuthToken(wallet.privateKey)
- Validate token by calling
authenticate(token)
Encrypting & decrypting data
Encryption
const data = Buffer.from('{"a":"123","b":123}', 'utf8')
const ciphertext = encryptData(
utils.arrayify(bob.publicKey),
utils.arrayify(alice.privateKey),
data
)
Decryption
const plaintext = decryptData(
utils.arrayify(bob.privateKey),
utils.arrayify(alice.publicKey),
ciphertext
)
Signing & verification
const data = Buffer.from('{"a":"123","b":123}', 'utf8')
const signature = await signatures.sign(
data,
privateKey,
)
Verification
const addr = signatures.getAddress(utils.arrayify(publicKey))
const res = await signatures.verify(data,signature,addr)