UNPKG

wowok

Version:

Wowok Blockchain TypeScript API

1 lines 1.57 kB
import{fromBase58,splitGenericParameters}from'../_deps/bcs/index.js';const TX_DIGEST_LENGTH=0x20;export function isValidTransactionDigest(a){try{const b=fromBase58(a);return b['length']===TX_DIGEST_LENGTH;}catch{return![];}}export const WOW_ADDRESS_LENGTH=0x20;export function isValidWowAddress(a){return isHex(a)&&getHexByteLength(a)===WOW_ADDRESS_LENGTH;}export function isValidWowObjectId(a){return isValidWowAddress(a);}function parseTypeTag(a){if(!a['includes']('::'))return a;return parseStructTag(a);}export function parseStructTag(a){const [b,c]=a['split']('::'),d=a['slice'](b['length']+c['length']+0x4),e=d['includes']('<')?d['slice'](0x0,d['indexOf']('<')):d,f=d['includes']('<')?splitGenericParameters(d['slice'](d['indexOf']('<')+0x1,d['lastIndexOf']('>')))['map'](g=>parseTypeTag(g['trim']())):[];return{'address':normalizeWowAddress(b),'module':c,'name':e,'typeParams':f};}export function normalizeStructTag(a){const {address:b,module:c,name:d,typeParams:e}=typeof a==='string'?parseStructTag(a):a,f=e?.['length']>0x0?'<'+e['map'](g=>typeof g==='string'?g:normalizeStructTag(g))['join'](',')+'>':'';return b+'::'+c+'::'+d+f;}export function normalizeWowAddress(a,b=![]){let c=a['toLowerCase']();return!b&&c['startsWith']('0x')&&(c=c['slice'](0x2)),'0x'+c['padStart'](WOW_ADDRESS_LENGTH*0x2,'0');}export function normalizeWowObjectId(a,b=![]){return normalizeWowAddress(a,b);}function isHex(a){return/^(0x|0X)?[a-fA-F0-9]+$/['test'](a)&&a['length']%0x2===0x0;}function getHexByteLength(a){return/^(0x|0X)/['test'](a)?(a['length']-0x2)/0x2:a['length']/0x2;}