UNPKG

@bridgesplit/rwa-token-sdk

Version:

RWA Token SDK for the development of permissioned tokens on SVM blockchains.

107 lines 6.24 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getIdentityAccountsWithFilter = exports.IDENTITY_ACCOUNT_OWNER_OFFSET = exports.IDENTITY_ACCOUNT_REGISTRY_OFFSET = exports.getIdentityAccount = exports.getIdentityRegistryAccountsWithFilter = exports.IDENTITY_REGISTRY_DELEGATE_OFFSET = exports.IDENTITY_REGISTRY_AUTHORITY_OFFSET = exports.IDENTITY_REGISTRY_ASSET_MINT_OFFSET = exports.getIdentityRegistryAccount = void 0; const utils_1 = require("./utils"); const web3_js_1 = require("@solana/web3.js"); /** * Retrieves identity registry account associated with a specific asset mint. * @param assetMint - The string representation of the asset mint. * @returns A promise resolving to {@link IdentityRegistryAccount}, or `undefined` if it doesn't exist. */ function getIdentityRegistryAccount(assetMint, provider) { return __awaiter(this, void 0, void 0, function* () { const identityRegistryProgram = (0, utils_1.getIdentityRegistryProgram)(provider); const identityRegistryPda = (0, utils_1.getIdentityRegistryPda)(assetMint); return identityRegistryProgram.account.identityRegistryAccount .fetch(identityRegistryPda) .then((account) => account) .catch(() => undefined); }); } exports.getIdentityRegistryAccount = getIdentityRegistryAccount; exports.IDENTITY_REGISTRY_ASSET_MINT_OFFSET = 9; exports.IDENTITY_REGISTRY_AUTHORITY_OFFSET = 41; exports.IDENTITY_REGISTRY_DELEGATE_OFFSET = 73; /** * Retrieves identity registry account associated with a specific asset mint. * @param assetMint - The string representation of the asset mint. * @returns A promise resolving to {@link IdentityRegistryAccount}, or `undefined` if it doesn't exist. */ function getIdentityRegistryAccountsWithFilter(filter, provider) { return __awaiter(this, void 0, void 0, function* () { const { assetMint, authority, delegate } = filter; const identityRegistryProgram = (0, utils_1.getIdentityRegistryProgram)(provider); const filters = []; if (assetMint) { filters.push({ memcmp: { offset: exports.IDENTITY_REGISTRY_ASSET_MINT_OFFSET, bytes: new web3_js_1.PublicKey(assetMint).toBase58() } }); } if (authority) { filters.push({ memcmp: { offset: exports.IDENTITY_REGISTRY_AUTHORITY_OFFSET, bytes: new web3_js_1.PublicKey(authority).toBase58() } }); } if (delegate) { filters.push({ memcmp: { offset: exports.IDENTITY_REGISTRY_DELEGATE_OFFSET, bytes: new web3_js_1.PublicKey(delegate).toBase58() } }); } const identityAccounts = yield provider.connection.getProgramAccounts(identityRegistryProgram.programId, { filters, }); return identityAccounts.map((account) => identityRegistryProgram.coder.accounts.decode("IdentityRegistryAccount", account.account.data)); }); } exports.getIdentityRegistryAccountsWithFilter = getIdentityRegistryAccountsWithFilter; /** * Retrieves a identity account associated with a specific asset mint and owner. * @param assetMint - The string representation of the asset mint. * @param owner - The string representation of the asset owner. * @returns A promise resolving to the {@link IdentityAccount}, or `undefined` if it doesn't exist. */ function getIdentityAccount(assetMint, owner, provider) { return __awaiter(this, void 0, void 0, function* () { const identityRegistryProgram = (0, utils_1.getIdentityRegistryProgram)(provider); const identityAccountPda = (0, utils_1.getIdentityAccountPda)(assetMint, owner); return identityRegistryProgram.account.identityAccount .fetch(identityAccountPda) .then((account) => account) .catch(() => undefined); }); } exports.getIdentityAccount = getIdentityAccount; exports.IDENTITY_ACCOUNT_REGISTRY_OFFSET = 9; exports.IDENTITY_ACCOUNT_OWNER_OFFSET = 41; /** * Retrieves all identity accounts associated with a specific asset mint and owner. * @param assetMint - The string representation of the asset mint. * @param owner - The string representation of the asset owner. * @returns A promise resolving to the {@link IdentityAccount}, or `undefined` if it doesn't exist. */ function getIdentityAccountsWithFilter(filter, provider) { return __awaiter(this, void 0, void 0, function* () { const { assetMint, registry, owner } = filter; const identityRegistryProgram = (0, utils_1.getIdentityRegistryProgram)(provider); const filters = []; if (assetMint) { const identityRegistryPda = (0, utils_1.getIdentityRegistryPda)(assetMint); filters.push({ memcmp: { offset: exports.IDENTITY_ACCOUNT_REGISTRY_OFFSET, bytes: identityRegistryPda.toBase58() } }); } if (registry) { filters.push({ memcmp: { offset: exports.IDENTITY_ACCOUNT_REGISTRY_OFFSET, bytes: new web3_js_1.PublicKey(registry).toBase58() } }); } if (owner) { filters.push({ memcmp: { offset: exports.IDENTITY_ACCOUNT_OWNER_OFFSET, bytes: new web3_js_1.PublicKey(owner).toBase58() } }); } const identityAccounts = yield provider.connection.getProgramAccounts(identityRegistryProgram.programId, { filters, }); return identityAccounts.map((account) => identityRegistryProgram.coder.accounts.decode("IdentityAccount", account.account.data)); }); } exports.getIdentityAccountsWithFilter = getIdentityAccountsWithFilter; //# sourceMappingURL=data.js.map