@ghostspeak/sdk
Version:
TypeScript SDK for GhostSpeak AI Agent Commerce Protocol - Production Ready Beta
156 lines (154 loc) • 6.03 kB
JavaScript
import { GHOSTSPEAK_MARKETPLACE_PROGRAM_ADDRESS, expectAddress, expectSome, getAccountMetaFactory } from './chunk-AWMGX3OX.js';
import { fixEncoderSize, getBytesEncoder, transformEncoder, getStructEncoder, getAddressEncoder, getU64Encoder, getI64Encoder, getU8Encoder, getOptionEncoder, addEncoderSizePrefix, getUtf8Encoder, getU32Encoder, getStructDecoder, fixDecoderSize, getAddressDecoder, getU64Decoder, getI64Decoder, getU8Decoder, getOptionDecoder, getBytesDecoder, addDecoderSizePrefix, getUtf8Decoder, getU32Decoder, combineCodec, getProgramDerivedAddress } from '@solana/kit';
var CREATE_AGENT_AUTHORIZATION_DISCRIMINATOR = new Uint8Array([
48,
219,
232,
202,
151,
97,
230,
20
]);
function getCreateAgentAuthorizationDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(
CREATE_AGENT_AUTHORIZATION_DISCRIMINATOR
);
}
function getCreateAgentAuthorizationInstructionDataEncoder() {
return transformEncoder(
getStructEncoder([
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
["authorizedSource", getAddressEncoder()],
["indexLimit", getU64Encoder()],
["expiresAt", getI64Encoder()],
["network", getU8Encoder()],
["signature", fixEncoderSize(getBytesEncoder(), 64)],
[
"nonce",
getOptionEncoder(
addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())
)
]
]),
(value) => ({
...value,
discriminator: CREATE_AGENT_AUTHORIZATION_DISCRIMINATOR
})
);
}
function getCreateAgentAuthorizationInstructionDataDecoder() {
return getStructDecoder([
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
["authorizedSource", getAddressDecoder()],
["indexLimit", getU64Decoder()],
["expiresAt", getI64Decoder()],
["network", getU8Decoder()],
["signature", fixDecoderSize(getBytesDecoder(), 64)],
[
"nonce",
getOptionDecoder(addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder()))
]
]);
}
function getCreateAgentAuthorizationInstructionDataCodec() {
return combineCodec(
getCreateAgentAuthorizationInstructionDataEncoder(),
getCreateAgentAuthorizationInstructionDataDecoder()
);
}
async function getCreateAgentAuthorizationInstructionAsync(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: true },
systemProgram: { value: input.systemProgram ?? null, isWritable: false }
};
const accounts = originalAccounts;
const args = { ...input };
if (!accounts.authorization.value) {
accounts.authorization.value = await getProgramDerivedAddress({
programAddress,
seeds: [
getBytesEncoder().encode(
new Uint8Array([97, 103, 101, 110, 116, 95, 97, 117, 116, 104])
),
getAddressEncoder().encode(expectAddress(accounts.agent.value)),
getAddressEncoder().encode(expectSome(args.authorizedSource)),
getOptionEncoder(
addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())
).encode(expectSome(args.nonce))
]
});
}
if (!accounts.systemProgram.value) {
accounts.systemProgram.value = "11111111111111111111111111111111";
}
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
return Object.freeze({
accounts: [
getAccountMeta(accounts.agent),
getAccountMeta(accounts.authorization),
getAccountMeta(accounts.authority),
getAccountMeta(accounts.systemProgram)
],
data: getCreateAgentAuthorizationInstructionDataEncoder().encode(
args
),
programAddress
});
}
function getCreateAgentAuthorizationInstruction(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: true },
systemProgram: { value: input.systemProgram ?? null, isWritable: false }
};
const accounts = originalAccounts;
const args = { ...input };
if (!accounts.systemProgram.value) {
accounts.systemProgram.value = "11111111111111111111111111111111";
}
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
return Object.freeze({
accounts: [
getAccountMeta(accounts.agent),
getAccountMeta(accounts.authorization),
getAccountMeta(accounts.authority),
getAccountMeta(accounts.systemProgram)
],
data: getCreateAgentAuthorizationInstructionDataEncoder().encode(
args
),
programAddress
});
}
function parseCreateAgentAuthorizationInstruction(instruction) {
if (instruction.accounts.length < 4) {
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(),
systemProgram: getNextAccount()
},
data: getCreateAgentAuthorizationInstructionDataDecoder().decode(
instruction.data
)
};
}
export { CREATE_AGENT_AUTHORIZATION_DISCRIMINATOR, getCreateAgentAuthorizationDiscriminatorBytes, getCreateAgentAuthorizationInstruction, getCreateAgentAuthorizationInstructionAsync, getCreateAgentAuthorizationInstructionDataCodec, getCreateAgentAuthorizationInstructionDataDecoder, getCreateAgentAuthorizationInstructionDataEncoder, parseCreateAgentAuthorizationInstruction };
//# sourceMappingURL=chunk-46QWY3MG.js.map
//# sourceMappingURL=chunk-46QWY3MG.js.map