Skip to content

generateViewingKey()

SIP Protocol API Reference v0.7.0


SIP Protocol API Reference / generateViewingKey

generateViewingKey(path?): ViewingKey

Defined in: @sip-protocol/sdk/dist/index-BYZbDjal.d.ts:3215

Generate a new viewing key for compliant privacy mode

Creates a cryptographically random viewing key that enables selective disclosure of transaction details to auditors or regulators while maintaining on-chain privacy.

Use Cases:

  • Regulatory compliance (AML/KYC audits)
  • Internal accounting and reconciliation
  • Voluntary disclosure to trusted parties
  • Hierarchical key management (via derivation paths)

Security:

  • Keep viewing keys secret - they decrypt all transaction details
  • Use hierarchical derivation for key management (BIP32-style paths)
  • Rotate keys periodically for forward secrecy

string

Hierarchical derivation path (BIP32-style, e.g., “m/0”, “m/44’/0’/0’“)

ViewingKey

Viewing key object with key, path, and hash

const masterKey = generateViewingKey('m/0')
console.log(masterKey.key) // "0xabc123..."
console.log(masterKey.path) // "m/0"
console.log(masterKey.hash) // "0xdef456..." (for identification)
const auditKey = generateViewingKey('m/0/audit')
const accountingKey = generateViewingKey('m/0/accounting')
// Share different keys with different departments
shareWithAuditor(auditKey)
shareWithAccounting(accountingKey)
const viewingKey = generateViewingKey()
const intent = await sip.createIntent({
input: { asset: { chain: 'near', symbol: 'NEAR', address: null, decimals: 24 }, amount: 100n },
output: { asset: { chain: 'zcash', symbol: 'ZEC', address: null, decimals: 8 }, minAmount: 0n, maxSlippage: 0.01 },
privacy: PrivacyLevel.COMPLIANT,
viewingKey: viewingKey.key,
})