SDKs

Official Node.js and Python SDKs for requesting approvals, waiting for decisions, and verifying signed receipts locally.

Key Concepts

Both SDKs handle authentication and polling. Creating a request returns a pending request_id; waiting returns a status with an optional decision receipt. Receiving an approved status does not verify the signature. Verify the receipt locally before executing.

Set SA_API_KEY to your live API key, SA_APPROVER_USER_ID to the intended approver's user ID, and SA_PINNED_PUBLIC_KEYS to a JSON map of signing key IDs to base64url SPKI public keys. Provision these trust anchors independently of the receipt and key discovery response. The examples require a passkey decision and reject sandbox receipts.

Node.js SDK

Important
This example requires the reviewed 0.1.1 verifier. Version 0.1.1 is not published to npm; an unversioned npm install @signedapproval/sdk currently installs 0.1.0, which does not provide the reviewed verification safeguards. Do not use 0.1.0 for this approval gate.

Ask the maintainer for a source checkout or archive containing the reviewed 0.1.1 changes. The source repository requires access; do not assume its default branch includes these changes. A version label alone does not establish that you have the reviewed source.

From that reviewed checkout's root, build and package the SDK locally:

bash
# Install the repository's TypeScript/Node type dependencies.
npm ci
cd sdk/node
npm ci
npm run build
npm pack
# Creates signedapproval-sdk-0.1.1.tgz in sdk/node.

In your application directory, install that tarball using its actual path. Confirm the installed version is 0.1.1. Save the example below as approval.mjs and run it with Node.js 18+:

bash
# Replace this path with the reviewed checkout's absolute path.
npm install /absolute/path/to/signedapproval/sdk/node/signedapproval-sdk-0.1.1.tgz
npm ls @signedapproval/sdk
node approval.mjs
javascript
import { SignedApproval } from '@signedapproval/sdk';
import { createHash } from 'node:crypto';

const required = name => {
  if (!process.env[name]) throw new Error('Set ' + name);
  return process.env[name];
};
const sha256 = text => createHash('sha256').update(text, 'utf8').digest('hex');
const sa = new SignedApproval(required('SA_API_KEY'));
const pinnedPublicKeys = JSON.parse(required('SA_PINNED_PUBLIC_KEYS'));
const expectedApprover = sha256(required('SA_APPROVER_USER_ID'));
const action = 'Deploy commit abc123 to production';

const request = await sa.requestApproval({
  action, ttl_seconds: 300, require_passkey: true,
}); // Returns pending with request_id.
const status = await sa.waitForDecision(request.request_id, {
  pollInterval: 3000, // milliseconds
  timeout: 300_000,
});
if (!status.decision) throw new Error('No signed decision: ' + status.status);

const proof = await sa.verifyReceipt(status.decision, {
  pinnedPublicKeys,
  expectedRequestId: request.request_id,
  expectedActionHash: sha256(action),
  expectedApprover,
  expectedMethod: 'passkey',
});
if (!proof.valid || proof.decision !== 'approved' || proof.sandbox !== false) {
  throw new Error('Approval refused: ' + (proof.failure_reason ?? proof.decision));
}
console.log('Verified approval for:', action);
// Execute only the exact action retained above, after this check.

verifyReceipt checks the Ed25519 signature, signed claims, expiry, and expected bindings. With pinnedPublicKeys, verification makes no network calls and rejects unknown key IDs. Without pins it discovers the public key from the service, so verification is local but key retrieval can use the network. Keep the default expiry and sandbox checks enabled for execution.

For server-side inspection, await sa.verify(request.request_id) asks the service to verify a stored decision; it also accepts the API's decision_id. This trusts the server's answer and does not perform your local expected-binding checks.

Python SDK

Install from the same reviewed 0.1.1 source checkout with the optional local verification dependency. Replace the path below; an unpinned PyPI install does not establish that you have this reviewed verifier:

bash
python -m pip install '/absolute/path/to/signedapproval/sdk/python[verify]'
python -c "import signedapproval; print(signedapproval.__version__)"

Use the same environment variables as the Node.js example:

python
import hashlib
import json
import os
from signedapproval import SignedApproval

sa = SignedApproval(os.environ["SA_API_KEY"])
pinned_keys = json.loads(os.environ["SA_PINNED_PUBLIC_KEYS"])
expected_approver = hashlib.sha256(
    os.environ["SA_APPROVER_USER_ID"].encode("utf-8")
).hexdigest()

def require_approval(action: str, ttl_seconds: int = 300) -> bool:
    request = sa.request_approval(
        action=action, ttl_seconds=ttl_seconds, require_passkey=True,
    )
    status = sa.wait_for_decision(
        request["request_id"], poll_interval=3.0, timeout=ttl_seconds,
    )  # Python intervals and timeouts are in seconds.
    if not status.get("decision"):
        return False
    proof = sa.verify_receipt(
        status["decision"],
        pinned_public_keys=pinned_keys,
        expected_request_id=request["request_id"],
        expected_action_hash=hashlib.sha256(action.encode("utf-8")).hexdigest(),
        expected_approver=expected_approver,
        expected_method="passkey",
    )
    return (proof["valid"] and proof["decision"] == "approved"
            and proof["sandbox"] is False)

action = "Deploy commit abc123 to production"
if not require_approval(action):
    raise RuntimeError("Approval refused")
print("Verified approval for:", action)
# Execute only the exact action retained above, after this check.

verify_receipt verifies locally; the pinned key map keeps verification fully offline. sa.verify(request_id) instead asks the server to verify a stored decision. Timeouts and pending-request expiry can raise SignedApprovalError; callers must stop execution on errors or a failed verification result.

LangChain and CrewAI Approval Gates

Reuse the Python require_approval helper above inside your agent tool or task. It uses the actual request_approval method and dictionary responses, and returns true only after local receipt verification. Keep your execution call behind the check:

python
# In the same module as require_approval above:
def approval_gate(commit: str) -> str:
    action = f"Deploy commit {commit} to production"
    if not require_approval(action):
        raise RuntimeError("Deployment blocked")
    # Add your deployment call here, using only the saved commit.
    return f"Approval verified for: {action}"
Important
Receipt v1 binds the exact UTF-8 action text, not context or structured tool arguments. Include every input that controls execution in the action and retain it locally. A valid signed rejection is still a rejection. Offline signature verification does not extend authorization past expiry.
Note
Both SDKs are open source. The Node.js SDK is in sdk/node/ and the Python SDK is in sdk/python/ within the SignedApproval repository.
Tip
The waitForDecision / wait_for_decision method handles polling automatically with configurable intervals and timeouts. Webhook consumers must also verify the signed receipt and expected bindings before executing.