TypeScript SDK

No Anchor dependency. CJS + ESM dual output. Zero external dependencies.

npm install intentguard-sdk

Hashing

computeIntentHash(action, params)

Computes a deterministic SHA-256 hash of an intent. Uses length-prefixed encoding to prevent concatenation ambiguity attacks.

import { computeIntentHash } from 'intentguard-sdk';

const hash: number[] = computeIntentHash('swap', {
  amount: 1_000_000_000,
  mint: 'EPjFWdd5...',
});
// Returns 32-byte array (number[])
ParamTypeDescription
actionstringAction name (e.g. "swap", "transfer", "stake")
paramsRecord<string, any>Parameters object. Keys are sorted for determinism.

Instructions

createCommitIntentInstruction(user, appId, hash, ttl?, programId?)

Creates a commit_intent instruction. Commits the intent hash on-chain with a TTL.

const ix = createCommitIntentInstruction(
  userPubkey,    // Signer wallet
  appId,         // Target app program ID
  hash,          // 32-byte intent hash
  300,           // TTL seconds (30-3600, default 300)
);
ParamTypeDefaultDescription
userPublicKeyWallet committing the intent (signer)
appIdPublicKeyTarget application identifier
hashnumber[] | Uint8Array32-byte SHA-256 intent hash
ttlnumber300Time-to-live in seconds
programIdPublicKeydevnet IDIntentGuard program ID

Accounts: intentPda (w), configPda (w), user (s,w), systemProgram

Data: discriminator(8) + appId(32) + hash(32) + ttl(8) = 80 bytes

createVerifyIntentInstruction(user, appId, hash, programId?)

Creates a verify_intent instruction. Verifies hash match, closes the PDA, and collects fee.

const ix = createVerifyIntentInstruction(userPubkey, appId, hash);

Accounts: intentPda (w), configPda (w), user (s,w), systemProgram

Data: discriminator(8) + hash(32) = 40 bytes

createRevokeIntentInstruction(user, appId, programId?)

Creates a revoke_intent instruction. Closes the PDA and refunds rent to the user.

const ix = createRevokeIntentInstruction(userPubkey, appId);

Accounts: intentPda (w), user (s,w)

Data: discriminator(8) + appId(32) = 40 bytes

Admin Instructions

createPauseProtocolInstruction(admin, programId?)

Pauses the protocol. Blocks commit and verify; revoke remains available.

createUnpauseProtocolInstruction(admin, programId?)

Unpauses the protocol.

createTransferAdminInstruction(admin, newAdmin, programId?)

Transfers admin authority to a new pubkey. Cannot transfer to zero address.

createUpdateFeeInstruction(admin, newFee, programId?)

Updates the per-verify fee. Maximum 0.1 SOL (100,000,000 lamports).

const ix = createUpdateFeeInstruction(
  adminPubkey,
  5_000_000,  // 0.005 SOL per verify
);

createWithdrawFeesInstruction(admin, amount, programId?)

Withdraws accumulated fees from the config PDA. Preserves rent-exempt minimum.

const ix = createWithdrawFeesInstruction(
  adminPubkey,
  500_000_000,  // 0.5 SOL
);

PDA Helpers

findIntentCommitPda(user, appId, programId?)

const [pda, bump] = findIntentCommitPda(userPubkey, appId);
// Seeds: [b"intent", user, app_id]

findConfigPda(programId?)

const [configPda, bump] = findConfigPda();
// Seeds: [b"config"]

Account Readers

getIntentCommit(connection, user, appId, programId?)

Fetches and deserializes an IntentCommit account. Returns null if not found.

const commit = await getIntentCommit(connection, userPubkey, appId);
if (commit) {
  console.log(commit.intentHash);   // Uint8Array(32)
  console.log(commit.committedAt);  // number (unix timestamp)
  console.log(commit.expiresAt);    // number (unix timestamp)
}

App Registry

lookupApp(appId)

Looks up an app by its program ID. Returns name, icon, and verification status. Tries remote registry first, falls back to bundled data.

const app = await lookupApp('JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4');
// { name: 'Jupiter', icon: '...', verified: true }

lookupAppSync(appId)

Synchronous lookup using bundled registry only. No network call.

isVerified(appId)

Returns true if the app is in the verified registry.

Constants

ConstantValueDescription
INTENT_GUARD_PROGRAM_ID4etWfDJ...Pix7Devnet program ID
DEFAULT_TTL3005 minutes
MAX_TTL36001 hour

Full auto-generated API docs: TypeDoc Reference