đ Create an API Key
An API key is required to use Lighthouse IPFS Walrus. You can generate one from the Walrus Dashboard (see Quick Start), SDK, or API.
To create an API key, use your Sui address as the publicKey:
- Request an authentication message from the message API.
- Sign the auth message with your Sui wallet or keypair to get the API key.
- JS SDK
- API
import axios from 'axios'
import lighthouse from '@lighthouse-web3/sdk'
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519'
const signAuthMessage = async (keypair, verificationMessage) => {
const message = new TextEncoder().encode(verificationMessage)
const { signature } = await keypair.signPersonalMessage(message)
return signature
}
const getApiKey = async () => {
const keypair = Ed25519Keypair.fromSecretKey('YOUR_SUI_PRIVATE_KEY')
const publicKey = keypair.toSuiAddress() // Ex: '0x8b2f...'
const verificationMessage = (
await axios.get(
`https://api.lighthouse.storage/api/auth/get_message?publicKey=${publicKey}`
)
).data
const signedMessage = await signAuthMessage(keypair, verificationMessage)
const response = await lighthouse.getApiKey(publicKey, signedMessage)
console.log(response)
}
getApiKey()
Browser wallet (Slush)
If you are signing in the browser, connect Slush (or another Sui wallet), fetch the verification message with your Sui address, then call signPersonalMessage on the connected wallet with the message bytes before calling lighthouse.getApiKey.
First, get an authentication message that must be signed to generate an API key. Use your Sui address as publicKey:
curl "https://api.lighthouse.storage/api/auth/get_message?publicKey=<SUI_ADDRESS>"
This returns a message string. Sign it with your Sui wallet, then submit the signature to create the API key:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"publicKey": "<SUI_ADDRESS>", "signedMessage": "<SIGNATURE>", "keyName": "my-walrus-key"}' \
https://api.lighthouse.storage/api/auth/create_api_key