withSecureBuffer()
SIP Protocol API Reference v0.7.0
SIP Protocol API Reference / withSecureBuffer
Function: withSecureBuffer()
Section titled “Function: withSecureBuffer()”withSecureBuffer<
T>(createSecret,useSecret):Promise<T>
Defined in: @sip-protocol/sdk/dist/index-BYZbDjal.d.ts:3486
Execute a function with a secret buffer and ensure cleanup
Provides a safer pattern for using secrets - the buffer is automatically wiped after the function completes (or throws).
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”createSecret
Section titled “createSecret”() => Uint8Array
Function to create the secret buffer
useSecret
Section titled “useSecret”(secret) => T | Promise<T>
Function that uses the secret
Returns
Section titled “Returns”Promise<T>
The result of useSecret
Example
Section titled “Example”const signature = await withSecureBuffer( () => generatePrivateKey(), async (privateKey) => { return signMessage(message, privateKey) })// privateKey is automatically wiped after signing