share

Shares access to encrypted data with other wallet addresses.

Signature

async function shareData(
  dataIdentifier: string,
  walletClient: Client<Transport, Chain, Account>,
  recipientAddresses: string[],
  config: ShareConfig,
  authorization: any,
  debug?: boolean
): Promise<void>

Description

The shareData function allows you to grant access to encrypted data to other wallets. This is useful when you want to share your encrypted data with other users while maintaining control over who can access it. The function requires the wallet that originally encrypted the data or has sharing permissions.

Important: This function uses EIP-7702 smart accounts powered by ZeroDev to make the experience gassless to the end user, which requires an authorization signature. This will not work with injected wallet providers like MetaMask, but is compatible with wallets where the private key is available or with embedded wallets such as Privy, Dynamic, and Turnkey.

Parameters

ParameterTypeRequiredDescription
dataIdentifierstringYesThe unique identifier of the encrypted data to share.
walletClientClient<Transport, Chain, Account>YesThe viem wallet client with the account that has permission to share the data.
recipientAddressesstring[]YesArray of wallet addresses to grant access to.
configShareConfigYesConfiguration object containing contract addresses and RPC endpoints.
authorizationanyYesThe EIP-7702 authorization signature. See signAuthorization for details.
debugbooleanNoWhen set to true, enables debug statements during the sharing process. Default is false.

ShareConfig Structure

Note: use init to automatically load the config.

{
  permissionsRegistryContractAddress: string, // Address of the permissions registry contract
  bundlerRpcUrl: string                        // RPC URL for the bundler (recommended: ZeroDev, but works with any account abstraction bundler/paymaster like biconomy, alchemy, etc)
}

Returns

Promise<void> - A Promise that resolves when the sharing operation is completed.

Examples

Basic Usage

// import relevantg libraries
import { init, share } from "@keypo/typescript-sdk";
import { http, createWalletClient } from "viem"
import { privateKeyToAccount } from "viem/accounts"
import { baseSepolia } from "viem/chains"
 
// load config
const config = await init("https://api.keypo.io");
 
// Create wallet client
const account = privateKeyToAccount('0x...');
const walletClient = createWalletClient({
  account,
  chain: baseSepolia,
  transport: http()
});
 
// Get authorization signature (needed for wallet to use smart account features)
const authorization = await walletClient.signAuthorization({
    contractAddress: config.kernelAddress as `0x${string}`, // Kernel V3.3 implementation address
});
 
await keypo.shareData(
  dataId,
  walletClient,
  recipientAddresses,
  config.shareConfig,
  authorization,
  true  // enable debug logs
);
 
console.log('Data shared successfully');

With Embedded Wallets

Keypo works with the following embedded wallets: Privy, Dynamic and Turnkey.

You need to pass the embedded wallet as Viem wallet client to the delete function in order for it to work properly. Please consult the embedded wallet’s documentation on guidelines for how to do that.

Authorization Requirements

This function requires an EIP-7702 authorization signature. The authorization must be signed by the account that has permission to delete the data.

Getting Authorization Signatures

With Known Private Keys

const authorization = await walletClient.signAuthorization({
    contractAddress: config.kernelAddress as `0x${string}`, // Kernel V3.3 implementation address
});

With Embedded Wallets

For Privy, Dynamic, and Turnkey integrations, consult the ZeroDev 7702 documentation for wallet-specific implementation details.

Notes

  • The function requires the wallet to be the same wallet that encrypted the data originally.
  • Use list or search to find the data identifier for data you want to share.
  • The function can share with multiple recipients in a single transaction.
  • The sharing operation is performed on-chain using EIP-7702 smart accounts and is gassless.
  • Debug mode will log transaction details and receipts for troubleshooting.

See Also