@tuwaio/siwx-core 0.2.1 → 1.0.0-feat-update-alpha.2.83013b6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +5 -5
- package/dist/index.mjs +5 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
'use strict';function v(e){let{domain:t,address:s,statement:i,uri:c,version:
|
|
2
|
-
`)}var m=class extends Error{constructor(s,i="SIWX_ERROR"){super(s);this.code=i;this.name="SiwxError",Object.setPrototypeOf(this,new.target.prototype);}code},f=class extends m{constructor(t){super(t,"SIWX_PARSE_ERROR"),this.name="SiwxParseError";}},x=class extends m{constructor(s){super(`CAIP-122 message validation failed: ${s.join(", ")}`,"SIWX_VALIDATION_ERROR");this.errors=s;this.name="SiwxValidationError";}errors},S=class extends m{constructor(t){super(t,"SIWX_VERIFICATION_ERROR"),this.name="SiwxVerificationError";}},w=class extends m{constructor(s){super(`SIWX session expired at ${s}`,"SIWX_EXPIRED_SESSION");this.expirationTime=s;this.name="SiwxExpiredSessionError";}expirationTime},E=class extends m{constructor(s){super(`Nonce has already been used: ${s}`,"SIWX_NONCE_REPLAY");this.nonce=s;this.name="SiwxNonceReplayError";}nonce},I=class extends m{constructor(s){super(`Unsupported CAIP-2 namespace: "${s}". Supported: eip155, solana`,"SIWX_UNSUPPORTED_NAMESPACE");this.namespace=s;this.name="SiwxUnsupportedNamespaceError";}namespace},
|
|
3
|
-
`);if(t.length<5)throw new f("Message is too short to be a valid CAIP-122 message.");let s=t[0]?.match(U);if(!s?.groups?.domain)throw new f('Invalid CAIP-122 header line. Expected: "{domain} wants you to sign in with your blockchain account:"');let i=s.groups.domain,c=t[1];if(!c)throw new f("Missing address on line 2.");if(t[2]!=="")throw new f("Expected blank line after address (line 3).");let
|
|
4
|
-
`))return "domain must not contain newline characters."}function B(e){if(!k.test(e))return `address must be CAIP-10 compliant (namespace:chainRef:address). Got: "${e}"`}function F(e){if(!W.test(e))return `uri must be a valid RFC 3986 URI starting with http(s)://. Got: "${e}"`}function G(e){if(!L.test(e))return `chainId must be a valid CAIP-2 identifier (namespace:reference). Got: "${e}"`}function j(e){if(!e||e.length<8)return `nonce must be at least 8 characters long. Got length: ${e?.length??0}`;if(!/^[a-zA-Z0-9]+$/.test(e))return `nonce must be alphanumeric. Got: "${e}"`}function
|
|
5
|
-
`)&&s.push("statement must not contain newline characters."),t?.policy){let
|
|
1
|
+
'use strict';function v(e){let{domain:t,address:s,statement:i,uri:c,version:o,chainId:n,nonce:a,issuedAt:d,expirationTime:l,notBefore:r,requestId:u,resources:g}=e,p=[`${t} wants you to sign in with your blockchain account:`,s,""];if(i&&p.push(i,""),p.push(`URI: ${c}`,`Version: ${o}`,`Chain ID: ${n}`,`Nonce: ${a}`,`Issued At: ${d}`),l&&p.push(`Expiration Time: ${l}`),r&&p.push(`Not Before: ${r}`),u&&p.push(`Request ID: ${u}`),g&&g.length>0){p.push("Resources:");for(let N of g)p.push(`- ${N}`);}return p.join(`
|
|
2
|
+
`)}var m=class extends Error{constructor(s,i="SIWX_ERROR"){super(s);this.code=i;this.name="SiwxError",Object.setPrototypeOf(this,new.target.prototype);}code},f=class extends m{constructor(t){super(t,"SIWX_PARSE_ERROR"),this.name="SiwxParseError";}},x=class extends m{constructor(s){super(`CAIP-122 message validation failed: ${s.join(", ")}`,"SIWX_VALIDATION_ERROR");this.errors=s;this.name="SiwxValidationError";}errors},S=class extends m{constructor(t){super(t,"SIWX_VERIFICATION_ERROR"),this.name="SiwxVerificationError";}},w=class extends m{constructor(s){super(`SIWX session expired at ${s}`,"SIWX_EXPIRED_SESSION");this.expirationTime=s;this.name="SiwxExpiredSessionError";}expirationTime},E=class extends m{constructor(s){super(`Nonce has already been used: ${s}`,"SIWX_NONCE_REPLAY");this.nonce=s;this.name="SiwxNonceReplayError";}nonce},I=class extends m{constructor(s){super(`Unsupported CAIP-2 namespace: "${s}". Supported: eip155, solana`,"SIWX_UNSUPPORTED_NAMESPACE");this.namespace=s;this.name="SiwxUnsupportedNamespaceError";}namespace},h=class extends m{constructor(t,s="SIWX_POLICY_VIOLATION"){super(t,s),this.name="SiwxPolicyViolationError";}},A=class extends h{constructor(s,i){let c=Array.isArray(s)?s.join(", "):s;super(`Domain mismatch. Expected: [${c}], Received: "${i}"`,"SIWX_DOMAIN_MISMATCH");this.expected=s;this.received=i;this.name="SiwxDomainMismatchError";}expected;received},$=class extends h{constructor(s,i){let c=Array.isArray(s)?s.join(", "):s;super(`URI mismatch. Expected: [${c}], Received: "${i}"`,"SIWX_URI_MISMATCH");this.expected=s;this.received=i;this.name="SiwxUriMismatchError";}expected;received},R=class extends h{constructor(s,i){super(`Chain ID "${i}" is not allowed. Allowed: [${s.join(", ")}]`,"SIWX_CHAIN_NOT_ALLOWED");this.allowedChainIds=s;this.received=i;this.name="SiwxChainNotAllowedError";}allowedChainIds;received},y=class extends h{constructor(s,i){super(`Message issuedAt "${s}" is older than the allowed max age of ${i} seconds`,"SIWX_ISSUED_AT_STALE");this.issuedAt=s;this.maxAgeSeconds=i;this.name="SiwxIssuedAtStaleError";}issuedAt;maxAgeSeconds},b=class extends h{constructor(s,i){super(`Message issuedAt "${s}" is in the future beyond allowed clock skew of ${i} seconds`,"SIWX_ISSUED_AT_FUTURE");this.issuedAt=s;this.clockSkewSeconds=i;this.name="SiwxIssuedAtFutureError";}issuedAt;clockSkewSeconds},M=class extends h{constructor(s){super(`Message not valid before ${s}`,"SIWX_NOT_BEFORE");this.notBefore=s;this.name="SiwxNotBeforeError";}notBefore},T=class extends h{constructor(s,i){super(`Session lifetime of ${s} seconds exceeds maximum allowed lifetime of ${i} seconds`,"SIWX_SESSION_LIFETIME_EXCEEDED");this.lifetimeSeconds=s;this.maxLifetimeSeconds=i;this.name="SiwxSessionLifetimeExceededError";}lifetimeSeconds;maxLifetimeSeconds};var U=/^(?<domain>.+) wants you to sign in with your blockchain account:$/,_=/^(?<key>[A-Za-z ]+): (?<value>.+)$/,P=/^- (?<resource>.+)$/;function O(e){let t=e.split(`
|
|
3
|
+
`);if(t.length<5)throw new f("Message is too short to be a valid CAIP-122 message.");let s=t[0]?.match(U);if(!s?.groups?.domain)throw new f('Invalid CAIP-122 header line. Expected: "{domain} wants you to sign in with your blockchain account:"');let i=s.groups.domain,c=t[1];if(!c)throw new f("Missing address on line 2.");if(t[2]!=="")throw new f("Expected blank line after address (line 3).");let o=3,n;if(t[o]&&!_.test(t[o])){if(n=t[o],o++,t[o]!=="")throw new f("Expected blank line after statement.");o++;}let a={},d=[],l=false;for(;o<t.length;){let u=t[o];if(u===void 0){o++;continue}if(u==="Resources:"){l=true,o++;continue}if(l){let p=u.match(P);if(p?.groups?.resource){d.push(p.groups.resource),o++;continue}l=false;}let g=u.match(_);g?.groups?.key&&g.groups.value&&(a[g.groups.key]=g.groups.value),o++;}let r=["URI","Version","Chain ID","Nonce","Issued At"];for(let u of r)if(!a[u])throw new f(`Missing required field in CAIP-122 message: "${u}"`);return {domain:i,address:c,statement:n,uri:a.URI,version:a.Version,chainId:a["Chain ID"],nonce:a.Nonce,issuedAt:a["Issued At"],expirationTime:a["Expiration Time"],notBefore:a["Not Before"],requestId:a["Request ID"],resources:d.length>0?d:void 0}}var W=/^https?:\/\/.+/,X=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/,k=/^[a-z0-9]+:[a-zA-Z0-9-]+:.+$/,L=/^[a-z0-9]+:[a-zA-Z0-9-]+$/;function V(e){if(!e||e.trim().length===0)return "domain must be a non-empty string.";if(e.includes(`
|
|
4
|
+
`))return "domain must not contain newline characters."}function B(e){if(!k.test(e))return `address must be CAIP-10 compliant (namespace:chainRef:address). Got: "${e}"`}function F(e){if(!W.test(e))return `uri must be a valid RFC 3986 URI starting with http(s)://. Got: "${e}"`}function G(e){if(!L.test(e))return `chainId must be a valid CAIP-2 identifier (namespace:reference). Got: "${e}"`}function j(e){if(!e||e.length<8)return `nonce must be at least 8 characters long. Got length: ${e?.length??0}`;if(!/^[a-zA-Z0-9]+$/.test(e))return `nonce must be alphanumeric. Got: "${e}"`}function C(e,t){if(!X.test(e))return `${t} must be a valid ISO 8601 datetime string. Got: "${e}"`}function q(e,t=new Date,s=0){let i=new Date(e);if(isNaN(i.getTime()))return `expirationTime is not a valid date: "${e}"`;if(i.getTime()+s*1e3<t.getTime())return `Message has expired. expirationTime was: ${e}`}function D(e,t,s=new Date){if(!t)return [];let i=[];if(t.expectedDomain!==void 0){let n=Array.isArray(t.expectedDomain)?t.expectedDomain:[t.expectedDomain];n.some(d=>d.toLowerCase()===e.domain.toLowerCase())||i.push(`Domain mismatch. Expected: [${n.join(", ")}], Received: "${e.domain}"`);}if(t.expectedUri!==void 0){let n=Array.isArray(t.expectedUri)?t.expectedUri:[t.expectedUri];n.some(d=>{if(e.uri===d)return true;let l=d.endsWith("/")?d.slice(0,-1):d;if(e.uri.startsWith(`${l}/`))return true;try{let r=new URL(e.uri),u=new URL(d);return r.origin.toLowerCase()===u.origin.toLowerCase()}catch{return false}})||i.push(`URI mismatch. Expected: [${n.join(", ")}], Received: "${e.uri}"`);}if(t.allowedChainIds!==void 0&&t.allowedChainIds.length>0){let n=String(e.chainId),a=n.includes(":")?n.split(":").pop():n;t.allowedChainIds.some(l=>{let r=String(l),u=r.includes(":")?r.split(":").pop():r;return r===n||u===a})||i.push(`Chain ID "${e.chainId}" is not allowed. Allowed: [${t.allowedChainIds.join(", ")}]`);}t.requireExpirationTime&&!e.expirationTime&&i.push("expirationTime is required by verification policy.");let c=t.clockSkewSeconds??60,o=new Date(e.issuedAt);if(isNaN(o.getTime())||(t.maxIssuedAtAgeSeconds!==void 0&&(s.getTime()-o.getTime())/1e3>t.maxIssuedAtAgeSeconds+c&&i.push(`Message issuedAt "${e.issuedAt}" is older than the allowed max age of ${t.maxIssuedAtAgeSeconds} seconds`),o.getTime()-s.getTime()>c*1e3&&i.push(`Message issuedAt "${e.issuedAt}" is in the future beyond allowed clock skew of ${c} seconds`)),e.notBefore&&t.enforceNotBefore!==false){let n=new Date(e.notBefore);isNaN(n.getTime())||n.getTime()-s.getTime()>c*1e3&&i.push(`Message not valid before ${e.notBefore}`);}if(t.maxSessionLifetimeSeconds!==void 0&&e.expirationTime){let n=new Date(e.expirationTime);if(!isNaN(n.getTime())&&!isNaN(o.getTime())){let a=(n.getTime()-o.getTime())/1e3;a>t.maxSessionLifetimeSeconds&&i.push(`Session lifetime of ${a} seconds exceeds maximum allowed lifetime of ${t.maxSessionLifetimeSeconds} seconds`);}}return i}function z(e,t){let s=[],i=V(e.domain);i&&s.push(i);let c=B(e.address);c&&s.push(c);let o=F(e.uri);o&&s.push(o),e.version!=="1"&&s.push(`version must be "1". Got: "${e.version}"`);let n=G(e.chainId);n&&s.push(n);let a=j(e.nonce);a&&s.push(a);let d=C(e.issuedAt,"issuedAt");d&&s.push(d);let l=t?.policy?.clockSkewSeconds??60;if(e.expirationTime){let r=C(e.expirationTime,"expirationTime");if(r)s.push(r);else if(!t?.skipExpiration){let u=q(e.expirationTime,new Date,l);u&&s.push(u);}}if(e.notBefore){let r=C(e.notBefore,"notBefore");r&&s.push(r);}if(e.statement&&e.statement.includes(`
|
|
5
|
+
`)&&s.push("statement must not contain newline characters."),t?.policy){let r=D(e,t.policy);s.push(...r);}return {valid:s.length===0,errors:s}}function Z(){let e=new Uint8Array(16);return globalThis.crypto.getRandomValues(e),Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function H(e,t,s){if(!e||!e.address||!t)return false;let i=e.address,c=i.startsWith("eip155:"),o=i.startsWith("solana:"),n=t.includes(":")?t.split(":").pop():t,a=i.includes(":")?i.split(":").pop():i,d=n.startsWith("0x")||t.startsWith("eip155:");if(d&&!c||!d&&!o||!(c?a.toLowerCase()===n.toLowerCase():a===n))return false;if(s!=null){let r=String(s),u=c?r.startsWith("eip155:")?r:`eip155:${r}`:r.startsWith("solana:")?r:`solana:${r}`;if(e.chainId&&e.chainId!==u&&e.chainId!==r)return false}return true}exports.SiwxChainNotAllowedError=R;exports.SiwxDomainMismatchError=A;exports.SiwxError=m;exports.SiwxExpiredSessionError=w;exports.SiwxIssuedAtFutureError=b;exports.SiwxIssuedAtStaleError=y;exports.SiwxNonceReplayError=E;exports.SiwxNotBeforeError=M;exports.SiwxParseError=f;exports.SiwxPolicyViolationError=h;exports.SiwxSessionLifetimeExceededError=T;exports.SiwxUnsupportedNamespaceError=I;exports.SiwxUriMismatchError=$;exports.SiwxValidationError=x;exports.SiwxVerificationError=S;exports.buildMessage=v;exports.generateNonce=Z;exports.isSessionMatchingTarget=H;exports.parseMessage=O;exports.validateMessage=z;exports.validatePolicy=D;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function v(e){let{domain:t,address:s,statement:i,uri:c,version:
|
|
2
|
-
`)}var m=class extends Error{constructor(s,i="SIWX_ERROR"){super(s);this.code=i;this.name="SiwxError",Object.setPrototypeOf(this,new.target.prototype);}code},f=class extends m{constructor(t){super(t,"SIWX_PARSE_ERROR"),this.name="SiwxParseError";}},x=class extends m{constructor(s){super(`CAIP-122 message validation failed: ${s.join(", ")}`,"SIWX_VALIDATION_ERROR");this.errors=s;this.name="SiwxValidationError";}errors},S=class extends m{constructor(t){super(t,"SIWX_VERIFICATION_ERROR"),this.name="SiwxVerificationError";}},w=class extends m{constructor(s){super(`SIWX session expired at ${s}`,"SIWX_EXPIRED_SESSION");this.expirationTime=s;this.name="SiwxExpiredSessionError";}expirationTime},E=class extends m{constructor(s){super(`Nonce has already been used: ${s}`,"SIWX_NONCE_REPLAY");this.nonce=s;this.name="SiwxNonceReplayError";}nonce},I=class extends m{constructor(s){super(`Unsupported CAIP-2 namespace: "${s}". Supported: eip155, solana`,"SIWX_UNSUPPORTED_NAMESPACE");this.namespace=s;this.name="SiwxUnsupportedNamespaceError";}namespace},
|
|
3
|
-
`);if(t.length<5)throw new f("Message is too short to be a valid CAIP-122 message.");let s=t[0]?.match(U);if(!s?.groups?.domain)throw new f('Invalid CAIP-122 header line. Expected: "{domain} wants you to sign in with your blockchain account:"');let i=s.groups.domain,c=t[1];if(!c)throw new f("Missing address on line 2.");if(t[2]!=="")throw new f("Expected blank line after address (line 3).");let
|
|
4
|
-
`))return "domain must not contain newline characters."}function B(e){if(!k.test(e))return `address must be CAIP-10 compliant (namespace:chainRef:address). Got: "${e}"`}function F(e){if(!W.test(e))return `uri must be a valid RFC 3986 URI starting with http(s)://. Got: "${e}"`}function G(e){if(!L.test(e))return `chainId must be a valid CAIP-2 identifier (namespace:reference). Got: "${e}"`}function j(e){if(!e||e.length<8)return `nonce must be at least 8 characters long. Got length: ${e?.length??0}`;if(!/^[a-zA-Z0-9]+$/.test(e))return `nonce must be alphanumeric. Got: "${e}"`}function
|
|
5
|
-
`)&&s.push("statement must not contain newline characters."),t?.policy){let
|
|
1
|
+
function v(e){let{domain:t,address:s,statement:i,uri:c,version:o,chainId:n,nonce:a,issuedAt:d,expirationTime:l,notBefore:r,requestId:u,resources:g}=e,p=[`${t} wants you to sign in with your blockchain account:`,s,""];if(i&&p.push(i,""),p.push(`URI: ${c}`,`Version: ${o}`,`Chain ID: ${n}`,`Nonce: ${a}`,`Issued At: ${d}`),l&&p.push(`Expiration Time: ${l}`),r&&p.push(`Not Before: ${r}`),u&&p.push(`Request ID: ${u}`),g&&g.length>0){p.push("Resources:");for(let N of g)p.push(`- ${N}`);}return p.join(`
|
|
2
|
+
`)}var m=class extends Error{constructor(s,i="SIWX_ERROR"){super(s);this.code=i;this.name="SiwxError",Object.setPrototypeOf(this,new.target.prototype);}code},f=class extends m{constructor(t){super(t,"SIWX_PARSE_ERROR"),this.name="SiwxParseError";}},x=class extends m{constructor(s){super(`CAIP-122 message validation failed: ${s.join(", ")}`,"SIWX_VALIDATION_ERROR");this.errors=s;this.name="SiwxValidationError";}errors},S=class extends m{constructor(t){super(t,"SIWX_VERIFICATION_ERROR"),this.name="SiwxVerificationError";}},w=class extends m{constructor(s){super(`SIWX session expired at ${s}`,"SIWX_EXPIRED_SESSION");this.expirationTime=s;this.name="SiwxExpiredSessionError";}expirationTime},E=class extends m{constructor(s){super(`Nonce has already been used: ${s}`,"SIWX_NONCE_REPLAY");this.nonce=s;this.name="SiwxNonceReplayError";}nonce},I=class extends m{constructor(s){super(`Unsupported CAIP-2 namespace: "${s}". Supported: eip155, solana`,"SIWX_UNSUPPORTED_NAMESPACE");this.namespace=s;this.name="SiwxUnsupportedNamespaceError";}namespace},h=class extends m{constructor(t,s="SIWX_POLICY_VIOLATION"){super(t,s),this.name="SiwxPolicyViolationError";}},A=class extends h{constructor(s,i){let c=Array.isArray(s)?s.join(", "):s;super(`Domain mismatch. Expected: [${c}], Received: "${i}"`,"SIWX_DOMAIN_MISMATCH");this.expected=s;this.received=i;this.name="SiwxDomainMismatchError";}expected;received},$=class extends h{constructor(s,i){let c=Array.isArray(s)?s.join(", "):s;super(`URI mismatch. Expected: [${c}], Received: "${i}"`,"SIWX_URI_MISMATCH");this.expected=s;this.received=i;this.name="SiwxUriMismatchError";}expected;received},R=class extends h{constructor(s,i){super(`Chain ID "${i}" is not allowed. Allowed: [${s.join(", ")}]`,"SIWX_CHAIN_NOT_ALLOWED");this.allowedChainIds=s;this.received=i;this.name="SiwxChainNotAllowedError";}allowedChainIds;received},y=class extends h{constructor(s,i){super(`Message issuedAt "${s}" is older than the allowed max age of ${i} seconds`,"SIWX_ISSUED_AT_STALE");this.issuedAt=s;this.maxAgeSeconds=i;this.name="SiwxIssuedAtStaleError";}issuedAt;maxAgeSeconds},b=class extends h{constructor(s,i){super(`Message issuedAt "${s}" is in the future beyond allowed clock skew of ${i} seconds`,"SIWX_ISSUED_AT_FUTURE");this.issuedAt=s;this.clockSkewSeconds=i;this.name="SiwxIssuedAtFutureError";}issuedAt;clockSkewSeconds},M=class extends h{constructor(s){super(`Message not valid before ${s}`,"SIWX_NOT_BEFORE");this.notBefore=s;this.name="SiwxNotBeforeError";}notBefore},T=class extends h{constructor(s,i){super(`Session lifetime of ${s} seconds exceeds maximum allowed lifetime of ${i} seconds`,"SIWX_SESSION_LIFETIME_EXCEEDED");this.lifetimeSeconds=s;this.maxLifetimeSeconds=i;this.name="SiwxSessionLifetimeExceededError";}lifetimeSeconds;maxLifetimeSeconds};var U=/^(?<domain>.+) wants you to sign in with your blockchain account:$/,_=/^(?<key>[A-Za-z ]+): (?<value>.+)$/,P=/^- (?<resource>.+)$/;function O(e){let t=e.split(`
|
|
3
|
+
`);if(t.length<5)throw new f("Message is too short to be a valid CAIP-122 message.");let s=t[0]?.match(U);if(!s?.groups?.domain)throw new f('Invalid CAIP-122 header line. Expected: "{domain} wants you to sign in with your blockchain account:"');let i=s.groups.domain,c=t[1];if(!c)throw new f("Missing address on line 2.");if(t[2]!=="")throw new f("Expected blank line after address (line 3).");let o=3,n;if(t[o]&&!_.test(t[o])){if(n=t[o],o++,t[o]!=="")throw new f("Expected blank line after statement.");o++;}let a={},d=[],l=false;for(;o<t.length;){let u=t[o];if(u===void 0){o++;continue}if(u==="Resources:"){l=true,o++;continue}if(l){let p=u.match(P);if(p?.groups?.resource){d.push(p.groups.resource),o++;continue}l=false;}let g=u.match(_);g?.groups?.key&&g.groups.value&&(a[g.groups.key]=g.groups.value),o++;}let r=["URI","Version","Chain ID","Nonce","Issued At"];for(let u of r)if(!a[u])throw new f(`Missing required field in CAIP-122 message: "${u}"`);return {domain:i,address:c,statement:n,uri:a.URI,version:a.Version,chainId:a["Chain ID"],nonce:a.Nonce,issuedAt:a["Issued At"],expirationTime:a["Expiration Time"],notBefore:a["Not Before"],requestId:a["Request ID"],resources:d.length>0?d:void 0}}var W=/^https?:\/\/.+/,X=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/,k=/^[a-z0-9]+:[a-zA-Z0-9-]+:.+$/,L=/^[a-z0-9]+:[a-zA-Z0-9-]+$/;function V(e){if(!e||e.trim().length===0)return "domain must be a non-empty string.";if(e.includes(`
|
|
4
|
+
`))return "domain must not contain newline characters."}function B(e){if(!k.test(e))return `address must be CAIP-10 compliant (namespace:chainRef:address). Got: "${e}"`}function F(e){if(!W.test(e))return `uri must be a valid RFC 3986 URI starting with http(s)://. Got: "${e}"`}function G(e){if(!L.test(e))return `chainId must be a valid CAIP-2 identifier (namespace:reference). Got: "${e}"`}function j(e){if(!e||e.length<8)return `nonce must be at least 8 characters long. Got length: ${e?.length??0}`;if(!/^[a-zA-Z0-9]+$/.test(e))return `nonce must be alphanumeric. Got: "${e}"`}function C(e,t){if(!X.test(e))return `${t} must be a valid ISO 8601 datetime string. Got: "${e}"`}function q(e,t=new Date,s=0){let i=new Date(e);if(isNaN(i.getTime()))return `expirationTime is not a valid date: "${e}"`;if(i.getTime()+s*1e3<t.getTime())return `Message has expired. expirationTime was: ${e}`}function D(e,t,s=new Date){if(!t)return [];let i=[];if(t.expectedDomain!==void 0){let n=Array.isArray(t.expectedDomain)?t.expectedDomain:[t.expectedDomain];n.some(d=>d.toLowerCase()===e.domain.toLowerCase())||i.push(`Domain mismatch. Expected: [${n.join(", ")}], Received: "${e.domain}"`);}if(t.expectedUri!==void 0){let n=Array.isArray(t.expectedUri)?t.expectedUri:[t.expectedUri];n.some(d=>{if(e.uri===d)return true;let l=d.endsWith("/")?d.slice(0,-1):d;if(e.uri.startsWith(`${l}/`))return true;try{let r=new URL(e.uri),u=new URL(d);return r.origin.toLowerCase()===u.origin.toLowerCase()}catch{return false}})||i.push(`URI mismatch. Expected: [${n.join(", ")}], Received: "${e.uri}"`);}if(t.allowedChainIds!==void 0&&t.allowedChainIds.length>0){let n=String(e.chainId),a=n.includes(":")?n.split(":").pop():n;t.allowedChainIds.some(l=>{let r=String(l),u=r.includes(":")?r.split(":").pop():r;return r===n||u===a})||i.push(`Chain ID "${e.chainId}" is not allowed. Allowed: [${t.allowedChainIds.join(", ")}]`);}t.requireExpirationTime&&!e.expirationTime&&i.push("expirationTime is required by verification policy.");let c=t.clockSkewSeconds??60,o=new Date(e.issuedAt);if(isNaN(o.getTime())||(t.maxIssuedAtAgeSeconds!==void 0&&(s.getTime()-o.getTime())/1e3>t.maxIssuedAtAgeSeconds+c&&i.push(`Message issuedAt "${e.issuedAt}" is older than the allowed max age of ${t.maxIssuedAtAgeSeconds} seconds`),o.getTime()-s.getTime()>c*1e3&&i.push(`Message issuedAt "${e.issuedAt}" is in the future beyond allowed clock skew of ${c} seconds`)),e.notBefore&&t.enforceNotBefore!==false){let n=new Date(e.notBefore);isNaN(n.getTime())||n.getTime()-s.getTime()>c*1e3&&i.push(`Message not valid before ${e.notBefore}`);}if(t.maxSessionLifetimeSeconds!==void 0&&e.expirationTime){let n=new Date(e.expirationTime);if(!isNaN(n.getTime())&&!isNaN(o.getTime())){let a=(n.getTime()-o.getTime())/1e3;a>t.maxSessionLifetimeSeconds&&i.push(`Session lifetime of ${a} seconds exceeds maximum allowed lifetime of ${t.maxSessionLifetimeSeconds} seconds`);}}return i}function z(e,t){let s=[],i=V(e.domain);i&&s.push(i);let c=B(e.address);c&&s.push(c);let o=F(e.uri);o&&s.push(o),e.version!=="1"&&s.push(`version must be "1". Got: "${e.version}"`);let n=G(e.chainId);n&&s.push(n);let a=j(e.nonce);a&&s.push(a);let d=C(e.issuedAt,"issuedAt");d&&s.push(d);let l=t?.policy?.clockSkewSeconds??60;if(e.expirationTime){let r=C(e.expirationTime,"expirationTime");if(r)s.push(r);else if(!t?.skipExpiration){let u=q(e.expirationTime,new Date,l);u&&s.push(u);}}if(e.notBefore){let r=C(e.notBefore,"notBefore");r&&s.push(r);}if(e.statement&&e.statement.includes(`
|
|
5
|
+
`)&&s.push("statement must not contain newline characters."),t?.policy){let r=D(e,t.policy);s.push(...r);}return {valid:s.length===0,errors:s}}function Z(){let e=new Uint8Array(16);return globalThis.crypto.getRandomValues(e),Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function H(e,t,s){if(!e||!e.address||!t)return false;let i=e.address,c=i.startsWith("eip155:"),o=i.startsWith("solana:"),n=t.includes(":")?t.split(":").pop():t,a=i.includes(":")?i.split(":").pop():i,d=n.startsWith("0x")||t.startsWith("eip155:");if(d&&!c||!d&&!o||!(c?a.toLowerCase()===n.toLowerCase():a===n))return false;if(s!=null){let r=String(s),u=c?r.startsWith("eip155:")?r:`eip155:${r}`:r.startsWith("solana:")?r:`solana:${r}`;if(e.chainId&&e.chainId!==u&&e.chainId!==r)return false}return true}export{R as SiwxChainNotAllowedError,A as SiwxDomainMismatchError,m as SiwxError,w as SiwxExpiredSessionError,b as SiwxIssuedAtFutureError,y as SiwxIssuedAtStaleError,E as SiwxNonceReplayError,M as SiwxNotBeforeError,f as SiwxParseError,h as SiwxPolicyViolationError,T as SiwxSessionLifetimeExceededError,I as SiwxUnsupportedNamespaceError,$ as SiwxUriMismatchError,x as SiwxValidationError,S as SiwxVerificationError,v as buildMessage,Z as generateNonce,H as isSessionMatchingTarget,O as parseMessage,z as validateMessage,D as validatePolicy};
|