UNPKG

@ghostspeak/sdk

Version:

TypeScript SDK for GhostSpeak AI Agent Commerce Protocol - Production Ready Beta

98 lines (96 loc) 3.35 kB
import { GHOSTSPEAK_MARKETPLACE_PROGRAM_ADDRESS, getAccountMetaFactory } from './chunk-AWMGX3OX.js'; import { fixEncoderSize, getBytesEncoder, transformEncoder, getStructEncoder, getOptionEncoder, addEncoderSizePrefix, getUtf8Encoder, getU32Encoder, getStructDecoder, fixDecoderSize, getOptionDecoder, getBytesDecoder, addDecoderSizePrefix, getUtf8Decoder, getU32Decoder, combineCodec } from '@solana/kit'; var REVOKE_AUTHORIZATION_DISCRIMINATOR = new Uint8Array([ 222, 179, 207, 59, 191, 78, 24, 248 ]); function getRevokeAuthorizationDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( REVOKE_AUTHORIZATION_DISCRIMINATOR ); } function getRevokeAuthorizationInstructionDataEncoder() { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], [ "nonce", getOptionEncoder( addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder()) ) ] ]), (value) => ({ ...value, discriminator: REVOKE_AUTHORIZATION_DISCRIMINATOR }) ); } function getRevokeAuthorizationInstructionDataDecoder() { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], [ "nonce", getOptionDecoder(addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())) ] ]); } function getRevokeAuthorizationInstructionDataCodec() { return combineCodec( getRevokeAuthorizationInstructionDataEncoder(), getRevokeAuthorizationInstructionDataDecoder() ); } function getRevokeAuthorizationInstruction(input, config) { const programAddress = config?.programAddress ?? GHOSTSPEAK_MARKETPLACE_PROGRAM_ADDRESS; const originalAccounts = { agent: { value: input.agent ?? null, isWritable: false }, authorization: { value: input.authorization ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false } }; const accounts = originalAccounts; const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ getAccountMeta(accounts.agent), getAccountMeta(accounts.authorization), getAccountMeta(accounts.authority) ], data: getRevokeAuthorizationInstructionDataEncoder().encode( args ), programAddress }); } function parseRevokeAuthorizationInstruction(instruction) { if (instruction.accounts.length < 3) { throw new Error("Not enough accounts"); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = instruction.accounts[accountIndex]; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { agent: getNextAccount(), authorization: getNextAccount(), authority: getNextAccount() }, data: getRevokeAuthorizationInstructionDataDecoder().decode( instruction.data ) }; } export { REVOKE_AUTHORIZATION_DISCRIMINATOR, getRevokeAuthorizationDiscriminatorBytes, getRevokeAuthorizationInstruction, getRevokeAuthorizationInstructionDataCodec, getRevokeAuthorizationInstructionDataDecoder, getRevokeAuthorizationInstructionDataEncoder, parseRevokeAuthorizationInstruction }; //# sourceMappingURL=chunk-A7ALCVUI.js.map //# sourceMappingURL=chunk-A7ALCVUI.js.map