This is the Go SDK for Lit Protocol. It provides a Go interface to interact with the Lit Protocol by wrapping the JavaScript SDK.
- Go 1.16 or higher
- Node.js 14 or higher
go get github.com/LIT-Protocol/lit-polyglot-sdk/go/lit_go_sdk
Here's a basic example of how to use the SDK:
package main
import (
"fmt"
"github.com/LIT-Protocol/lit-polyglot-sdk/go/lit_go_sdk"
)
func main() {
// Create a new client
client, err := lit_go_sdk.NewLitNodeClient()
if err != nil {
panic(err)
}
defer client.Close()
// Set auth token (your private key)
_, err = client.SetAuthToken("your-private-key")
if err != nil {
panic(err)
}
// Initialize the client with network config
_, err = client.New(lit_go_sdk.LitNodeClientConfig{
LitNetwork: "datil-test", // or your preferred network
Debug: true,
})
if err != nil {
panic(err)
}
// Connect to the Lit network
_, err = client.Connect()
if err != nil {
panic(err)
}
}
You can execute JavaScript code across the Lit Network. First, get session signatures, then execute the code:
// Get session signatures
sessionSigsResult, err := client.GetSessionSigs(lit_go_sdk.SessionSigsParams{
Chain: "ethereum",
Expiration: time.Now().Add(10 * time.Minute).Format(time.RFC3339),
ResourceAbilityRequests: []interface{}{
map[string]interface{}{
"resource": map[string]interface{}{
"resource": "*",
"resourcePrefix": "lit-litaction",
},
"ability": "lit-action-execution",
},
},
})
sessionSigs := sessionSigsResult["sessionSigs"].(map[string]interface{})
// Execute JavaScript
result, err := client.ExecuteJs(lit_go_sdk.ExecuteJsParams{
Code: `
(async () => {
console.log("Testing executeJs endpoint");
Lit.Actions.setResponse({response: "Test successful"});
})()
`,
JsParams: map[string]interface{}{},
SessionSigs: sessionSigs,
})
The SDK supports minting and using PKPs. Here's how to mint a new PKP using ETH wallet authentication:
// Create SIWE message
siweResult, err := client.CreateSiweMessage(lit_go_sdk.CreateSiweMessageParams{
URI: "http://localhost:3092",
Expiration: time.Now().Add(10 * time.Minute).Format(time.RFC3339),
Resources: []interface{}{
map[string]interface{}{
"resource": map[string]interface{}{
"resource": "*",
"resourcePrefix": "lit-litaction",
},
"ability": "lit-action-execution",
},
},
WalletAddress: "your-eth-wallet-address",
})
// Generate auth signature
authSigResult, err := client.GenerateAuthSig(siweResult["siweMessage"].(string))
// Mint PKP
mintResult, err := client.MintWithAuth(lit_go_sdk.MintWithAuthParams{
AuthMethod: map[string]interface{}{
"authMethodType": 1, // EthWallet
"accessToken": authSigResult["authSig"],
},
Scopes: []int{1},
})
The SDK provides functionality to encrypt and decrypt strings with access control conditions. Here's how to use it:
// First, get session signatures
sessionSigsResult, err := client.GetSessionSigs(lit_go_sdk.SessionSigsParams{
Chain: "ethereum",
Expiration: time.Now().Add(10 * time.Minute).Format(time.RFC3339),
ResourceAbilityRequests: []interface{}{
map[string]interface{}{
"resource": map[string]interface{}{
"resource": "*",
"resourcePrefix": "lit-litaction",
},
"ability": "lit-action-execution",
},
},
})
sessionSigs := sessionSigsResult["sessionSigs"].(map[string]interface{})
// Encrypt a string
testString := "Hello, World!"
encryptResult, err := client.EncryptString(lit_go_sdk.EncryptStringParams{
DataToEncrypt: testString,
AccessControlConditions: []interface{}{
map[string]interface{}{
"contractAddress": "",
"standardContractType": "",
"chain": "ethereum",
"method": "",
"parameters": []string{":userAddress"},
"returnValueTest": map[string]interface{}{
"comparator": "=",
"value": "your-eth-wallet-address",
},
},
},
})
// Decrypt the string
decryptResult, err := client.DecryptString(lit_go_sdk.DecryptStringParams{
Chain: "ethereum",
Ciphertext: encryptResult["ciphertext"].(string),
DataToEncryptHash: encryptResult["dataToEncryptHash"].(string),
AccessControlConditions: []interface{}{
map[string]interface{}{
"contractAddress": "",
"standardContractType": "",
"chain": "ethereum",
"method": "",
"parameters": []string{":userAddress"},
"returnValueTest": map[string]interface{}{
"comparator": "=",
"value": "your-eth-wallet-address",
},
},
},
SessionSigs: sessionSigs,
})
fmt.Printf("Decrypted string: %s\n", decryptResult["decryptedString"])
The encryption is tied to access control conditions, which means only users who meet those conditions (like owning a specific wallet address) can decrypt the data.
Creates a new Lit Protocol client.
Sets the authentication token (private key) for the Lit Protocol.
Initializes the client with network configuration.
Connects to the Lit network.
Executes JavaScript code on the Lit network.
Gets session signatures for authentication.
Creates a Sign-In with Ethereum message.
Generates an authentication signature.
Mints a new PKP with authentication.
Encrypts a string with access control conditions.
Decrypts a string using session signatures and access control conditions.
Closes the client and stops the Node.js server.
All methods return an error as their second return value. You should always check for errors before using the results.
Contributions are welcome! Please feel free to submit a Pull Request.