charms-js
Version:
TypeScript SDK for decoding Bitcoin transactions containing Charms data
38 lines (37 loc) • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppType = void 0;
exports.getAppType = getAppType;
exports.extractAppId = extractAppId;
var AppType;
(function (AppType) {
AppType["NFT"] = "nft";
AppType["TOKEN"] = "token";
AppType["UNKNOWN"] = "unknown";
})(AppType || (exports.AppType = AppType = {}));
// Determines app type from app string
function getAppType(appString) {
if (!appString || typeof appString !== 'string') {
return AppType.UNKNOWN;
}
if (appString.startsWith('n/')) {
return AppType.NFT;
}
else if (appString.startsWith('t/')) {
return AppType.TOKEN;
}
else {
return AppType.UNKNOWN;
}
}
// Extracts app ID from app string format "n/[app_id]/..." or "t/[app_id]/..."
function extractAppId(appString) {
if (!appString || typeof appString !== 'string') {
return '';
}
const parts = appString.split('/');
if (parts.length >= 2) {
return parts[1];
}
return appString;
}