Get keys bound to a wallet address
The Get Keys Bound to Wallet Address API lets you get the public keys associated with a wallet address.
While this API can be used by clients, getting the keys bound to a wallet address is primarily a function of account servicing entities.
When an authorization server receives a signed grant request, the server makes a call to get the public keys bound to the wallet address. Then, when a client makes a request to a resource server, the resource server calls the auth server to ensure the signature of the request corresponds to the wallet address’s public JWK. This allows the server to ensure the client is who it says it is.
Before you begin
Section titled “Before you begin”We recommend creating a wallet account on the test wallet. Creating an account allows you to test your client against the Open Payments APIs by using an ILP-enabled wallet funded with play money.
Retrieve the public keys for a wallet address
Section titled “Retrieve the public keys for a wallet address”// Import dependenciesimport { createAuthenticatedClient } from '@interledger/open-payments'
// Initialize clientconst client = await createAuthenticatedClient({ walletAddressUrl: WALLET_ADDRESS, privateKey: PRIVATE_KEY_PATH, keyId: KEY_ID})
// Get wallet address keysconst walletAddressKeys = await client.walletAddress.getKeys({ url: WALLET_ADDRESS})
// Outputconsole.log('WALLET ADDRESS KEYS:', JSON.stringify(walletAddressKeys, null, 2))For TypeScript, run tsx path/to/directory/index.ts. View full TS source
For JavaScript, run node path/to/directory/index.js. View full JS source
// Import dependenciesuse open_payments::client::api::UnauthenticatedResources;use open_payments::snippets::utils::{create_unauthenticated_client, get_env_var, load_env};
// Initialize clientlet client = create_unauthenticated_client();
// Get wallet address keyslet wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?;let wallet_address = client.wallet_address().get(&wallet_address_url).await?;
// Outputprintln!("Retrieved wallet address: {wallet_address:#?}");println!("Retrieved keys: {keys:#?}");// Import dependenciesuse OpenPayments\AuthClient;use OpenPayments\Config\Config;
// Initialize client$config = new Config($WALLET_ADDRESS);$opClient = new AuthClient($config);
// Get wallet address keys$walletKeys = $opClient->walletAddress()->getKeys([ 'url' => $config->getWalletAddressUrl()]);
// Outputecho 'WALLET ADDRESS KEYS: ' . PHP_EOL . print_r($walletKeys, true);package main
// Import dependenciesimport ( "context" "encoding/json" "fmt" "log"
op "github.com/interledger/open-payments-go"
)
func main() { // Initialize client client := op.NewClient()
// Get wallet address keys walletAddressKeys, err := client.WalletAddress.GetKeys(context.TODO(), op.WalletAddressGetKeysParams{ URL: WALLET_ADDRESS_URL, }) if err != nil { log.Fatalf("Error fetching wallet address keys: %v\n", err) }
// Output walletAddressKeysJSON, err := json.MarshalIndent(walletAddressKeys, "", " ") if err != nil { log.Fatalf("Error marshaling wallet address keys: %v\n", err) } fmt.Println("WALLET ADDRESS KEYS:", string(walletAddressKeysJSON))}// Import dependenciesimport org.interledger.openpayments.httpclient.OpenPaymentsHttpClient;import org.interledger.openpayments.IOpenPaymentsClient;
// Initialize clientvar client = OpenPaymentsHttpClient.defaultClient("WalletAddress","PrivateKeyPEM","KeyId");
// Get wallet address keysvar keys = client.walletAddress().keys("https://cloudninebank.example.com/customer");
// Outputlog.info("WALLET_ADDRESS_KEYS: {}", keys);// Import dependenciesusing Microsoft.Extensions.DependencyInjection;using Newtonsoft.Json;using OpenPayments.Sdk.Clients;using OpenPayments.Sdk.Extensions;
// Initialize clientvar client = new ServiceCollection() .UseOpenPayments(opts => { opts.UseUnauthenticatedClient = true; }) .BuildServiceProvider() .GetRequiredService<IUnauthenticatedClient>();
// Get wallet address keysvar walletAddressKeys = await client.GetWalletAddressKeysAsync(WALLET_ADDRESS);
// OutputConsole.WriteLine($"WALLET ADDRESS KEYS: {JsonConvert.SerializeObject(walletAddressKeys, Formatting.Indented)}");