Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

caip-50

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

caip-50 - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

5

dist/cjs/utils.js

@@ -37,3 +37,4 @@ "use strict";

return caip10;
const [address, chainId] = caip10.split("@");
const [namespace, reference, address] = caip10.split(":");
const chainId = formatCaip2({ namespace, reference });
return { chainId, address };

@@ -43,3 +44,3 @@ }

function formatCaip10(params) {
return `${params.address}@${params.chainId}`;
return `${params.chainId}:${params.address}`;
}

@@ -46,0 +47,0 @@ exports.formatCaip10 = formatCaip10;

@@ -28,7 +28,8 @@ import u8a from "uint8arrays";

return caip10;
const [address, chainId] = caip10.split("@");
const [namespace, reference, address] = caip10.split(":");
const chainId = formatCaip2({ namespace, reference });
return { chainId, address };
}
export function formatCaip10(params) {
return `${params.address}@${params.chainId}`;
return `${params.chainId}:${params.address}`;
}

@@ -35,0 +36,0 @@ export function parseCaip2(caip2) {

2

dist/umd/index.min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("caip50",[],t):"object"==typeof exports?exports.caip50=t():e.caip50=t()}(this,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=6)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CAIP2_NAMESPACE_FORMATS=t.CAIP50_ENCODING=t.CAIP50_PREFIX=t.CAIP50_CODE=void 0,t.CAIP50_CODE=202,t.CAIP50_PREFIX="z",t.CAIP50_ENCODING="base58btc",t.CAIP2_NAMESPACE_FORMATS={bip122:{code:0,namespace:"bip122",encoding:{chainId:"base16",address:"base58btc"}},eip155:{code:1,namespace:"eip155",encoding:{chainId:"base10",address:"base16"}},cosmos:{code:2,namespace:"cosmos",encoding:{chainId:"utf8",address:"bech32"}},polkadot:{code:3,namespace:"polkadot",encoding:{chainId:"base16",address:"base58btc"}},filecoin:{code:4,namespace:"filecoin",encoding:{chainId:"utf8",address:"base58btc"}},lip9:{code:5,namespace:"lip9",encoding:{chainId:"base16",address:"base32"}},eosio:{code:6,namespace:"eosio",encoding:{chainId:"base16",address:"utf8"}},tezos:{code:7,namespace:"tezos",encoding:{chainId:"base58btc",address:"base58btc"}}}},function(e,t,r){"use strict";const n=r(11),o=r(12),c=r(13),i=r(14),a=r(19),s=r(20);e.exports={compare:n,concat:o,equals:c,fromString:i,toString:a,xor:s}},function(e,t,r){"use strict";const n=new TextDecoder,o=new TextEncoder;e.exports={decodeText:e=>n.decode(e),encodeText:e=>o.encode(e),concat:function(e,t){const r=new Uint8Array(t);let n=0;for(const t of e)r.set(t,n),n+=t.length;return r}}},function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.formatAddress=t.parseAddress=t.addHexPrefix=t.removeHexPrefix=t.formatCaip2=t.parseCaip2=t.formatCaip10=t.parseCaip10=t.getCaip2NamespaceFormatByCode=t.getCaip2NamespaceFormat=t.checksum=void 0;const o=n(r(1)),c=r(21),i=r(0);function a(e){return e.replace(/^0x/,"")}function s(e){return e.startsWith("0x")?e:"0x"+e}t.checksum=function(e){let t=o.default.xor(Uint8Array.from([e[0]]),Uint8Array.from([e[1]]));for(let r=2;r<e.length;r++)t=o.default.xor(t,Uint8Array.from([e[r]]));return t},t.getCaip2NamespaceFormat=function(e){const t=i.CAIP2_NAMESPACE_FORMATS[e.toLowerCase()];if(void 0===t)throw new Error("Invalid or missing format for CAIP-2 namespace: "+e);return t},t.getCaip2NamespaceFormatByCode=function(e){const t=Object.values(i.CAIP2_NAMESPACE_FORMATS).find(t=>t.code===e);if(void 0===t)throw new Error("Invalid or missing format for code: "+e);return t},t.parseCaip10=function(e){if("string"!=typeof e)return e;const[t,r]=e.split("@");return{chainId:r,address:t}},t.formatCaip10=function(e){return`${e.address}@${e.chainId}`},t.parseCaip2=function(e){if("string"!=typeof e)return e;const[t,r]=e.split(":");return{namespace:t,reference:r}},t.formatCaip2=function(e){return`${e.namespace}:${e.reference}`},t.removeHexPrefix=a,t.addHexPrefix=s,t.parseAddress=function(e,t){if("bech32"===t){const{words:t}=c.bech32.decode(e);return new Uint8Array(t)}return"base16"===t&&(e=a(e)),o.default.fromString(e,t)},t.formatAddress=function(e,t){if("bech32"===t)return c.bech32.encode("cosmos",e);let r=o.default.toString(e,t);return"base16"===t&&(r=s(r)),r}},function(e,t,r){e.exports={encode:r(8),decode:r(9),encodingLength:r(10)}},function(e,t,r){"use strict";const n=r(15),{encodeText:o,decodeText:c,concat:i}=r(2);function a(e){if(Object.prototype.hasOwnProperty.call(n.names,e))return n.names[e];if(Object.prototype.hasOwnProperty.call(n.codes,e))return n.codes[e];throw new Error("Unsupported encoding: "+e)}(t=e.exports=function(e,t){if(!t)throw new Error("requires an encoded Uint8Array");const{name:r,codeBuf:n}=a(e);return function(e,t){a(e).decode(c(t))}(r,t),i([n,t],n.length+t.length)}).encode=function(e,t){const r=a(e),n=o(r.encode(t));return i([r.codeBuf,n],r.codeBuf.length+n.length)},t.decode=function(e){e instanceof Uint8Array&&(e=c(e));const t=e[0];return["f","F","v","V","t","T","b","B","c","C","h","k","K"].includes(t)&&(e=e.toLowerCase()),a(e[0]).decode(e.substring(1))},t.isEncoded=function(e){if(e instanceof Uint8Array&&(e=c(e)),"[object String]"!==Object.prototype.toString.call(e))return!1;try{return a(e[0]).name}catch(e){return!1}},t.encoding=a,t.encodingFromData=function(e){return e instanceof Uint8Array&&(e=c(e)),a(e[0])};const s=Object.freeze(n.names),f=Object.freeze(n.codes);t.names=s,t.codes=f},function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(0),t),o(r(7),t),o(r(22),t),o(r(23),t),o(r(3),t)},function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.decode=t.sliceCaip50Bytes=t.fromCaip50String=void 0;const o=n(r(4)),c=n(r(1)),i=r(0),a=r(3);function s(e){return c.default.fromString(e.replace(i.CAIP50_PREFIX,""),i.CAIP50_ENCODING)}function f(e){const t=o.default.decode(e.slice(0,2)),r=e.slice(2,3)[0],n=4+o.default.decode(e.slice(3,4)),c=e.slice(4,n),i=n+1,a=i+o.default.decode(e.slice(n,i));return{code:t,namespaceCode:r,chainIdBytes:c,addressBytes:e.slice(i,a)}}t.fromCaip50String=s,t.sliceCaip50Bytes=f,t.decode=function(e){const t=s(e),{code:r,namespaceCode:n,chainIdBytes:o,addressBytes:d}=f(t);if(r!==i.CAIP50_CODE)throw new Error("Invalid CAIP-50 code");const u=t.slice(-1),l=a.checksum(t);if(!c.default.compare(l,u))throw new Error("Invalid CAIP-50 checksum");const{namespace:p,encoding:h}=a.getCaip2NamespaceFormatByCode(n),b=c.default.toString(o,h.chainId);return{chainId:a.formatCaip2({namespace:p,reference:b}),address:a.formatAddress(d,h.address)}}},function(e,t){e.exports=function e(t,n,o){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw e.bytes=0,new RangeError("Could not encode varint");n=n||[];var c=o=o||0;for(;t>=r;)n[o++]=255&t|128,t/=128;for(;-128&t;)n[o++]=255&t|128,t>>>=7;return n[o]=0|t,e.bytes=o-c+1,n};var r=Math.pow(2,31)},function(e,t){e.exports=function e(t,r){var n,o=0,c=0,i=r=r||0,a=t.length;do{if(i>=a||c>49)throw e.bytes=0,new RangeError("Could not decode varint");n=t[i++],o+=c<28?(127&n)<<c:(127&n)*Math.pow(2,c),c+=7}while(n>=128);return e.bytes=i-r,o}},function(e,t){var r=Math.pow(2,7),n=Math.pow(2,14),o=Math.pow(2,21),c=Math.pow(2,28),i=Math.pow(2,35),a=Math.pow(2,42),s=Math.pow(2,49),f=Math.pow(2,56),d=Math.pow(2,63);e.exports=function(e){return e<r?1:e<n?2:e<o?3:e<c?4:e<i?5:e<a?6:e<s?7:e<f?8:e<d?9:10}},function(e,t,r){"use strict";e.exports=function(e,t){for(let r=0;r<e.byteLength;r++){if(e[r]<t[r])return-1;if(e[r]>t[r])return 1}return e.byteLength>t.byteLength?1:e.byteLength<t.byteLength?-1:0}},function(e,t,r){"use strict";e.exports=function(e,t){t||(t=e.reduce((e,t)=>e+t.length,0));const r=new Uint8Array(t);let n=0;for(const t of e)r.set(t,n),n+=t.length;return r}},function(e,t,r){"use strict";e.exports=function(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}},function(e,t,r){"use strict";const{encoding:n}=r(5),o=new TextEncoder;e.exports=function(e,t="utf8"){return"utf8"===t||"utf-8"===t?o.encode(e):"ascii"===t?function(e){const t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}(e):n(t).decode(e)}},function(e,t,r){"use strict";const n=r(16),o=r(17),{rfc4648:c}=r(18),{decodeText:i,encodeText:a}=r(2),s=[["identity","\0",()=>({encode:i,decode:a}),""],["base2","0",c(1),"01"],["base8","7",c(3),"01234567"],["base10","9",n,"0123456789"],["base16","f",c(4),"0123456789abcdef"],["base16upper","F",c(4),"0123456789ABCDEF"],["base32hex","v",c(5),"0123456789abcdefghijklmnopqrstuv"],["base32hexupper","V",c(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV"],["base32hexpad","t",c(5),"0123456789abcdefghijklmnopqrstuv="],["base32hexpadupper","T",c(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV="],["base32","b",c(5),"abcdefghijklmnopqrstuvwxyz234567"],["base32upper","B",c(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],["base32pad","c",c(5),"abcdefghijklmnopqrstuvwxyz234567="],["base32padupper","C",c(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="],["base32z","h",c(5),"ybndrfg8ejkmcpqxot1uwisza345h769"],["base36","k",n,"0123456789abcdefghijklmnopqrstuvwxyz"],["base36upper","K",n,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"],["base58btc","z",n,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],["base58flickr","Z",n,"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"],["base64","m",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],["base64pad","M",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],["base64url","u",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],["base64urlpad","U",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="]],f=s.reduce((e,t)=>(e[t[0]]=new o(t[0],t[1],t[2],t[3]),e),{}),d=s.reduce((e,t)=>(e[t[1]]=f[t[0]],e),{});e.exports={names:f,codes:d}},function(e,t,r){"use strict";e.exports=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var o=e.charAt(n),c=o.charCodeAt(0);if(255!==t[c])throw new TypeError(o+" is ambiguous");t[c]=n}var i=e.length,a=e.charAt(0),s=Math.log(i)/Math.log(256),f=Math.log(256)/Math.log(i);function d(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;var r=0;if(" "!==e[r]){for(var n=0,o=0;e[r]===a;)n++,r++;for(var c=(e.length-r)*s+1>>>0,f=new Uint8Array(c);e[r];){var d=t[e.charCodeAt(r)];if(255===d)return;for(var u=0,l=c-1;(0!==d||u<o)&&-1!==l;l--,u++)d+=i*f[l]>>>0,f[l]=d%256>>>0,d=d/256>>>0;if(0!==d)throw new Error("Non-zero carry");o=u,r++}if(" "!==e[r]){for(var p=c-o;p!==c&&0===f[p];)p++;for(var h=new Uint8Array(n+(c-p)),b=n;p!==c;)h[b++]=f[p++];return h}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var r=0,n=0,o=0,c=t.length;o!==c&&0===t[o];)o++,r++;for(var s=(c-o)*f+1>>>0,d=new Uint8Array(s);o!==c;){for(var u=t[o],l=0,p=s-1;(0!==u||l<n)&&-1!==p;p--,l++)u+=256*d[p]>>>0,d[p]=u%i>>>0,u=u/i>>>0;if(0!==u)throw new Error("Non-zero carry");n=l,o++}for(var h=s-n;h!==s&&0===d[h];)h++;for(var b=a.repeat(r);h<s;++h)b+=e.charAt(d[h]);return b},decodeUnsafe:d,decode:function(e){var t=d(e);if(t)return t;throw new Error("Non-base"+i+" character")}}}},function(e,t,r){"use strict";const{encodeText:n}=r(2);e.exports=class{constructor(e,t,r,o){this.name=e,this.code=t,this.codeBuf=n(this.code),this.alphabet=o,this.codec=r(o)}encode(e){return this.codec.encode(e)}decode(e){for(const t of e)if(this.alphabet&&this.alphabet.indexOf(t)<0)throw new Error(`invalid character '${t}' in '${e}'`);return this.codec.decode(e)}}},function(e,t,r){"use strict";e.exports={rfc4648:e=>t=>({encode:r=>((e,t,r)=>{const n="="===t[t.length-1],o=(1<<r)-1;let c="",i=0,a=0;for(let n=0;n<e.length;++n)for(a=a<<8|e[n],i+=8;i>r;)i-=r,c+=t[o&a>>i];if(i&&(c+=t[o&a<<r-i]),n)for(;c.length*r&7;)c+="=";return c})(r,t,e),decode:r=>((e,t,r)=>{const n={};for(let e=0;e<t.length;++e)n[t[e]]=e;let o=e.length;for(;"="===e[o-1];)--o;const c=new Uint8Array(o*r/8|0);let i=0,a=0,s=0;for(let t=0;t<o;++t){const o=n[e[t]];if(void 0===o)throw new SyntaxError("Invalid character "+e[t]);a=a<<r|o,i+=r,i>=8&&(i-=8,c[s++]=255&a>>i)}if(i>=r||255&a<<8-i)throw new SyntaxError("Unexpected end of data");return c})(r,t,e)})}},function(e,t,r){"use strict";const{encoding:n}=r(5),o=new TextDecoder("utf8");e.exports=function(e,t="utf8"){return"utf8"===t||"utf-8"===t?o.decode(e):"ascii"===t?function(e){let t="";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t}(e):n(t).encode(e)}},function(e,t,r){"use strict";e.exports=function(e,t){if(e.length!==t.length)throw new Error("Inputs should have the same length");const r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.bech32m=t.bech32=void 0;const n="qpzry9x8gf2tvdw0s3jn54khce6mua7l",o={};for(let e=0;e<n.length;e++){const t=n.charAt(e);o[t]=e}function c(e){const t=e>>25;return(33554431&e)<<5^996825010&-(t>>0&1)^642813549&-(t>>1&1)^513874426&-(t>>2&1)^1027748829&-(t>>3&1)^705979059&-(t>>4&1)}function i(e){let t=1;for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+e+")";t=c(t)^n>>5}t=c(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=c(t)^31&n}return t}function a(e,t,r,n){let o=0,c=0;const i=(1<<r)-1,a=[];for(let n=0;n<e.length;++n)for(o=o<<t|e[n],c+=t;c>=r;)c-=r,a.push(o>>c&i);if(n)c>0&&a.push(o<<r-c&i);else{if(c>=t)return"Excess padding";if(o<<r-c&i)return"Non-zero padding"}return a}function s(e){return a(e,8,5,!0)}function f(e){const t=a(e,5,8,!1);if(Array.isArray(t))return t}function d(e){const t=a(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function u(e){let t;function r(e,r){if(r=r||90,e.length<8)return e+" too short";if(e.length>r)return"Exceeds length limit";const n=e.toLowerCase(),a=e.toUpperCase();if(e!==n&&e!==a)return"Mixed-case string "+e;const s=(e=n).lastIndexOf("1");if(-1===s)return"No separator character for "+e;if(0===s)return"Missing prefix for "+e;const f=e.slice(0,s),d=e.slice(s+1);if(d.length<6)return"Data too short";let u=i(f);if("string"==typeof u)return u;const l=[];for(let e=0;e<d.length;++e){const t=d.charAt(e),r=o[t];if(void 0===r)return"Unknown character "+t;u=c(u)^r,e+6>=d.length||l.push(r)}return u!==t?"Invalid checksum for "+e:{prefix:f,words:l}}return t="bech32"===e?1:734539939,{decodeUnsafe:function(e,t){const n=r(e,t);if("object"==typeof n)return n},decode:function(e,t){const n=r(e,t);if("object"==typeof n)return n;throw new Error(n)},encode:function(e,r,o){if(o=o||90,e.length+7+r.length>o)throw new TypeError("Exceeds length limit");let a=i(e=e.toLowerCase());if("string"==typeof a)throw new Error(a);let s=e+"1";for(let e=0;e<r.length;++e){const t=r[e];if(t>>5!=0)throw new Error("Non 5-bit word");a=c(a)^t,s+=n.charAt(t)}for(let e=0;e<6;++e)a=c(a);a^=t;for(let e=0;e<6;++e){s+=n.charAt(a>>5*(5-e)&31)}return s},toWords:s,fromWordsUnsafe:f,fromWords:d}}t.bech32=u("bech32"),t.bech32m=u("bech32m")},function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.encode=void 0;const o=n(r(4)),c=n(r(1)),i=r(0),a=r(3);t.encode=function(e){const{address:t,chainId:r}=a.parseCaip10(e),{namespace:n,reference:s}=a.parseCaip2(r),{code:f,encoding:d}=a.getCaip2NamespaceFormat(n),u=c.default.fromString(s,d.chainId),l=a.parseAddress(t,d.address),p=c.default.concat([o.default.encode(i.CAIP50_CODE),Uint8Array.from([f]),o.default.encode(u.length),u,o.default.encode(l.length),l]),h=a.checksum(p),b=c.default.concat([p,h]);return i.CAIP50_PREFIX+c.default.toString(b,i.CAIP50_ENCODING)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0})}])}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("caip50",[],t):"object"==typeof exports?exports.caip50=t():e.caip50=t()}(this,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=6)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CAIP2_NAMESPACE_FORMATS=t.CAIP50_ENCODING=t.CAIP50_PREFIX=t.CAIP50_CODE=void 0,t.CAIP50_CODE=202,t.CAIP50_PREFIX="z",t.CAIP50_ENCODING="base58btc",t.CAIP2_NAMESPACE_FORMATS={bip122:{code:0,namespace:"bip122",encoding:{chainId:"base16",address:"base58btc"}},eip155:{code:1,namespace:"eip155",encoding:{chainId:"base10",address:"base16"}},cosmos:{code:2,namespace:"cosmos",encoding:{chainId:"utf8",address:"bech32"}},polkadot:{code:3,namespace:"polkadot",encoding:{chainId:"base16",address:"base58btc"}},filecoin:{code:4,namespace:"filecoin",encoding:{chainId:"utf8",address:"base58btc"}},lip9:{code:5,namespace:"lip9",encoding:{chainId:"base16",address:"base32"}},eosio:{code:6,namespace:"eosio",encoding:{chainId:"base16",address:"utf8"}},tezos:{code:7,namespace:"tezos",encoding:{chainId:"base58btc",address:"base58btc"}}}},function(e,t,r){"use strict";const n=r(11),o=r(12),c=r(13),i=r(14),a=r(19),s=r(20);e.exports={compare:n,concat:o,equals:c,fromString:i,toString:a,xor:s}},function(e,t,r){"use strict";const n=new TextDecoder,o=new TextEncoder;e.exports={decodeText:e=>n.decode(e),encodeText:e=>o.encode(e),concat:function(e,t){const r=new Uint8Array(t);let n=0;for(const t of e)r.set(t,n),n+=t.length;return r}}},function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.formatAddress=t.parseAddress=t.addHexPrefix=t.removeHexPrefix=t.formatCaip2=t.parseCaip2=t.formatCaip10=t.parseCaip10=t.getCaip2NamespaceFormatByCode=t.getCaip2NamespaceFormat=t.checksum=void 0;const o=n(r(1)),c=r(21),i=r(0);function a(e){return`${e.namespace}:${e.reference}`}function s(e){return e.replace(/^0x/,"")}function f(e){return e.startsWith("0x")?e:"0x"+e}t.checksum=function(e){let t=o.default.xor(Uint8Array.from([e[0]]),Uint8Array.from([e[1]]));for(let r=2;r<e.length;r++)t=o.default.xor(t,Uint8Array.from([e[r]]));return t},t.getCaip2NamespaceFormat=function(e){const t=i.CAIP2_NAMESPACE_FORMATS[e.toLowerCase()];if(void 0===t)throw new Error("Invalid or missing format for CAIP-2 namespace: "+e);return t},t.getCaip2NamespaceFormatByCode=function(e){const t=Object.values(i.CAIP2_NAMESPACE_FORMATS).find(t=>t.code===e);if(void 0===t)throw new Error("Invalid or missing format for code: "+e);return t},t.parseCaip10=function(e){if("string"!=typeof e)return e;const[t,r,n]=e.split(":");return{chainId:a({namespace:t,reference:r}),address:n}},t.formatCaip10=function(e){return`${e.chainId}:${e.address}`},t.parseCaip2=function(e){if("string"!=typeof e)return e;const[t,r]=e.split(":");return{namespace:t,reference:r}},t.formatCaip2=a,t.removeHexPrefix=s,t.addHexPrefix=f,t.parseAddress=function(e,t){if("bech32"===t){const{words:t}=c.bech32.decode(e);return new Uint8Array(t)}return"base16"===t&&(e=s(e)),o.default.fromString(e,t)},t.formatAddress=function(e,t){if("bech32"===t)return c.bech32.encode("cosmos",e);let r=o.default.toString(e,t);return"base16"===t&&(r=f(r)),r}},function(e,t,r){e.exports={encode:r(8),decode:r(9),encodingLength:r(10)}},function(e,t,r){"use strict";const n=r(15),{encodeText:o,decodeText:c,concat:i}=r(2);function a(e){if(Object.prototype.hasOwnProperty.call(n.names,e))return n.names[e];if(Object.prototype.hasOwnProperty.call(n.codes,e))return n.codes[e];throw new Error("Unsupported encoding: "+e)}(t=e.exports=function(e,t){if(!t)throw new Error("requires an encoded Uint8Array");const{name:r,codeBuf:n}=a(e);return function(e,t){a(e).decode(c(t))}(r,t),i([n,t],n.length+t.length)}).encode=function(e,t){const r=a(e),n=o(r.encode(t));return i([r.codeBuf,n],r.codeBuf.length+n.length)},t.decode=function(e){e instanceof Uint8Array&&(e=c(e));const t=e[0];return["f","F","v","V","t","T","b","B","c","C","h","k","K"].includes(t)&&(e=e.toLowerCase()),a(e[0]).decode(e.substring(1))},t.isEncoded=function(e){if(e instanceof Uint8Array&&(e=c(e)),"[object String]"!==Object.prototype.toString.call(e))return!1;try{return a(e[0]).name}catch(e){return!1}},t.encoding=a,t.encodingFromData=function(e){return e instanceof Uint8Array&&(e=c(e)),a(e[0])};const s=Object.freeze(n.names),f=Object.freeze(n.codes);t.names=s,t.codes=f},function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(0),t),o(r(7),t),o(r(22),t),o(r(23),t),o(r(3),t)},function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.decode=t.sliceCaip50Bytes=t.fromCaip50String=void 0;const o=n(r(4)),c=n(r(1)),i=r(0),a=r(3);function s(e){return c.default.fromString(e.replace(i.CAIP50_PREFIX,""),i.CAIP50_ENCODING)}function f(e){const t=o.default.decode(e.slice(0,2)),r=e.slice(2,3)[0],n=4+o.default.decode(e.slice(3,4)),c=e.slice(4,n),i=n+1,a=i+o.default.decode(e.slice(n,i));return{code:t,namespaceCode:r,chainIdBytes:c,addressBytes:e.slice(i,a)}}t.fromCaip50String=s,t.sliceCaip50Bytes=f,t.decode=function(e){const t=s(e),{code:r,namespaceCode:n,chainIdBytes:o,addressBytes:d}=f(t);if(r!==i.CAIP50_CODE)throw new Error("Invalid CAIP-50 code");const u=t.slice(-1),l=a.checksum(t);if(!c.default.compare(l,u))throw new Error("Invalid CAIP-50 checksum");const{namespace:p,encoding:h}=a.getCaip2NamespaceFormatByCode(n),b=c.default.toString(o,h.chainId);return{chainId:a.formatCaip2({namespace:p,reference:b}),address:a.formatAddress(d,h.address)}}},function(e,t){e.exports=function e(t,n,o){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw e.bytes=0,new RangeError("Could not encode varint");n=n||[];var c=o=o||0;for(;t>=r;)n[o++]=255&t|128,t/=128;for(;-128&t;)n[o++]=255&t|128,t>>>=7;return n[o]=0|t,e.bytes=o-c+1,n};var r=Math.pow(2,31)},function(e,t){e.exports=function e(t,r){var n,o=0,c=0,i=r=r||0,a=t.length;do{if(i>=a||c>49)throw e.bytes=0,new RangeError("Could not decode varint");n=t[i++],o+=c<28?(127&n)<<c:(127&n)*Math.pow(2,c),c+=7}while(n>=128);return e.bytes=i-r,o}},function(e,t){var r=Math.pow(2,7),n=Math.pow(2,14),o=Math.pow(2,21),c=Math.pow(2,28),i=Math.pow(2,35),a=Math.pow(2,42),s=Math.pow(2,49),f=Math.pow(2,56),d=Math.pow(2,63);e.exports=function(e){return e<r?1:e<n?2:e<o?3:e<c?4:e<i?5:e<a?6:e<s?7:e<f?8:e<d?9:10}},function(e,t,r){"use strict";e.exports=function(e,t){for(let r=0;r<e.byteLength;r++){if(e[r]<t[r])return-1;if(e[r]>t[r])return 1}return e.byteLength>t.byteLength?1:e.byteLength<t.byteLength?-1:0}},function(e,t,r){"use strict";e.exports=function(e,t){t||(t=e.reduce((e,t)=>e+t.length,0));const r=new Uint8Array(t);let n=0;for(const t of e)r.set(t,n),n+=t.length;return r}},function(e,t,r){"use strict";e.exports=function(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}},function(e,t,r){"use strict";const{encoding:n}=r(5),o=new TextEncoder;e.exports=function(e,t="utf8"){return"utf8"===t||"utf-8"===t?o.encode(e):"ascii"===t?function(e){const t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}(e):n(t).decode(e)}},function(e,t,r){"use strict";const n=r(16),o=r(17),{rfc4648:c}=r(18),{decodeText:i,encodeText:a}=r(2),s=[["identity","\0",()=>({encode:i,decode:a}),""],["base2","0",c(1),"01"],["base8","7",c(3),"01234567"],["base10","9",n,"0123456789"],["base16","f",c(4),"0123456789abcdef"],["base16upper","F",c(4),"0123456789ABCDEF"],["base32hex","v",c(5),"0123456789abcdefghijklmnopqrstuv"],["base32hexupper","V",c(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV"],["base32hexpad","t",c(5),"0123456789abcdefghijklmnopqrstuv="],["base32hexpadupper","T",c(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV="],["base32","b",c(5),"abcdefghijklmnopqrstuvwxyz234567"],["base32upper","B",c(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],["base32pad","c",c(5),"abcdefghijklmnopqrstuvwxyz234567="],["base32padupper","C",c(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="],["base32z","h",c(5),"ybndrfg8ejkmcpqxot1uwisza345h769"],["base36","k",n,"0123456789abcdefghijklmnopqrstuvwxyz"],["base36upper","K",n,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"],["base58btc","z",n,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],["base58flickr","Z",n,"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"],["base64","m",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],["base64pad","M",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],["base64url","u",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],["base64urlpad","U",c(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="]],f=s.reduce((e,t)=>(e[t[0]]=new o(t[0],t[1],t[2],t[3]),e),{}),d=s.reduce((e,t)=>(e[t[1]]=f[t[0]],e),{});e.exports={names:f,codes:d}},function(e,t,r){"use strict";e.exports=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var o=e.charAt(n),c=o.charCodeAt(0);if(255!==t[c])throw new TypeError(o+" is ambiguous");t[c]=n}var i=e.length,a=e.charAt(0),s=Math.log(i)/Math.log(256),f=Math.log(256)/Math.log(i);function d(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;var r=0;if(" "!==e[r]){for(var n=0,o=0;e[r]===a;)n++,r++;for(var c=(e.length-r)*s+1>>>0,f=new Uint8Array(c);e[r];){var d=t[e.charCodeAt(r)];if(255===d)return;for(var u=0,l=c-1;(0!==d||u<o)&&-1!==l;l--,u++)d+=i*f[l]>>>0,f[l]=d%256>>>0,d=d/256>>>0;if(0!==d)throw new Error("Non-zero carry");o=u,r++}if(" "!==e[r]){for(var p=c-o;p!==c&&0===f[p];)p++;for(var h=new Uint8Array(n+(c-p)),b=n;p!==c;)h[b++]=f[p++];return h}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var r=0,n=0,o=0,c=t.length;o!==c&&0===t[o];)o++,r++;for(var s=(c-o)*f+1>>>0,d=new Uint8Array(s);o!==c;){for(var u=t[o],l=0,p=s-1;(0!==u||l<n)&&-1!==p;p--,l++)u+=256*d[p]>>>0,d[p]=u%i>>>0,u=u/i>>>0;if(0!==u)throw new Error("Non-zero carry");n=l,o++}for(var h=s-n;h!==s&&0===d[h];)h++;for(var b=a.repeat(r);h<s;++h)b+=e.charAt(d[h]);return b},decodeUnsafe:d,decode:function(e){var t=d(e);if(t)return t;throw new Error("Non-base"+i+" character")}}}},function(e,t,r){"use strict";const{encodeText:n}=r(2);e.exports=class{constructor(e,t,r,o){this.name=e,this.code=t,this.codeBuf=n(this.code),this.alphabet=o,this.codec=r(o)}encode(e){return this.codec.encode(e)}decode(e){for(const t of e)if(this.alphabet&&this.alphabet.indexOf(t)<0)throw new Error(`invalid character '${t}' in '${e}'`);return this.codec.decode(e)}}},function(e,t,r){"use strict";e.exports={rfc4648:e=>t=>({encode:r=>((e,t,r)=>{const n="="===t[t.length-1],o=(1<<r)-1;let c="",i=0,a=0;for(let n=0;n<e.length;++n)for(a=a<<8|e[n],i+=8;i>r;)i-=r,c+=t[o&a>>i];if(i&&(c+=t[o&a<<r-i]),n)for(;c.length*r&7;)c+="=";return c})(r,t,e),decode:r=>((e,t,r)=>{const n={};for(let e=0;e<t.length;++e)n[t[e]]=e;let o=e.length;for(;"="===e[o-1];)--o;const c=new Uint8Array(o*r/8|0);let i=0,a=0,s=0;for(let t=0;t<o;++t){const o=n[e[t]];if(void 0===o)throw new SyntaxError("Invalid character "+e[t]);a=a<<r|o,i+=r,i>=8&&(i-=8,c[s++]=255&a>>i)}if(i>=r||255&a<<8-i)throw new SyntaxError("Unexpected end of data");return c})(r,t,e)})}},function(e,t,r){"use strict";const{encoding:n}=r(5),o=new TextDecoder("utf8");e.exports=function(e,t="utf8"){return"utf8"===t||"utf-8"===t?o.decode(e):"ascii"===t?function(e){let t="";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t}(e):n(t).encode(e)}},function(e,t,r){"use strict";e.exports=function(e,t){if(e.length!==t.length)throw new Error("Inputs should have the same length");const r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.bech32m=t.bech32=void 0;const n="qpzry9x8gf2tvdw0s3jn54khce6mua7l",o={};for(let e=0;e<n.length;e++){const t=n.charAt(e);o[t]=e}function c(e){const t=e>>25;return(33554431&e)<<5^996825010&-(t>>0&1)^642813549&-(t>>1&1)^513874426&-(t>>2&1)^1027748829&-(t>>3&1)^705979059&-(t>>4&1)}function i(e){let t=1;for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+e+")";t=c(t)^n>>5}t=c(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=c(t)^31&n}return t}function a(e,t,r,n){let o=0,c=0;const i=(1<<r)-1,a=[];for(let n=0;n<e.length;++n)for(o=o<<t|e[n],c+=t;c>=r;)c-=r,a.push(o>>c&i);if(n)c>0&&a.push(o<<r-c&i);else{if(c>=t)return"Excess padding";if(o<<r-c&i)return"Non-zero padding"}return a}function s(e){return a(e,8,5,!0)}function f(e){const t=a(e,5,8,!1);if(Array.isArray(t))return t}function d(e){const t=a(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function u(e){let t;function r(e,r){if(r=r||90,e.length<8)return e+" too short";if(e.length>r)return"Exceeds length limit";const n=e.toLowerCase(),a=e.toUpperCase();if(e!==n&&e!==a)return"Mixed-case string "+e;const s=(e=n).lastIndexOf("1");if(-1===s)return"No separator character for "+e;if(0===s)return"Missing prefix for "+e;const f=e.slice(0,s),d=e.slice(s+1);if(d.length<6)return"Data too short";let u=i(f);if("string"==typeof u)return u;const l=[];for(let e=0;e<d.length;++e){const t=d.charAt(e),r=o[t];if(void 0===r)return"Unknown character "+t;u=c(u)^r,e+6>=d.length||l.push(r)}return u!==t?"Invalid checksum for "+e:{prefix:f,words:l}}return t="bech32"===e?1:734539939,{decodeUnsafe:function(e,t){const n=r(e,t);if("object"==typeof n)return n},decode:function(e,t){const n=r(e,t);if("object"==typeof n)return n;throw new Error(n)},encode:function(e,r,o){if(o=o||90,e.length+7+r.length>o)throw new TypeError("Exceeds length limit");let a=i(e=e.toLowerCase());if("string"==typeof a)throw new Error(a);let s=e+"1";for(let e=0;e<r.length;++e){const t=r[e];if(t>>5!=0)throw new Error("Non 5-bit word");a=c(a)^t,s+=n.charAt(t)}for(let e=0;e<6;++e)a=c(a);a^=t;for(let e=0;e<6;++e){s+=n.charAt(a>>5*(5-e)&31)}return s},toWords:s,fromWordsUnsafe:f,fromWords:d}}t.bech32=u("bech32"),t.bech32m=u("bech32m")},function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.encode=void 0;const o=n(r(4)),c=n(r(1)),i=r(0),a=r(3);t.encode=function(e){const{address:t,chainId:r}=a.parseCaip10(e),{namespace:n,reference:s}=a.parseCaip2(r),{code:f,encoding:d}=a.getCaip2NamespaceFormat(n),u=c.default.fromString(s,d.chainId),l=a.parseAddress(t,d.address),p=c.default.concat([o.default.encode(i.CAIP50_CODE),Uint8Array.from([f]),o.default.encode(u.length),u,o.default.encode(l.length),l]),h=a.checksum(p),b=c.default.concat([p,h]);return i.CAIP50_PREFIX+c.default.toString(b,i.CAIP50_ENCODING)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0})}])}));
{
"name": "caip-50",
"description": "CAIP-50 Multi-Chain Account Identifier",
"version": "0.1.0",
"version": "0.2.0",
"author": "Pedro Gomes <github.com/pedrouid>",

@@ -6,0 +6,0 @@ "license": "MIT",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc