@alien_org/sso-sdk-core 1.0.13 → 1.0.14

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.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var g=(a,s,t)=>new Promise((o,n)=>{var r=l=>{try{u(t.next(l))}catch(d){n(d)}},c=l=>{try{u(t.throw(l))}catch(d){n(d)}},u=l=>l.done?o(l.value):Promise.resolve(l.value).then(r,c);u((t=t.apply(a,s)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("zod/v4-mini"),$=require("js-sha256"),i=require("@solana/web3.js"),R=e.z.object({code_challenge:e.z.string(),code_challenge_method:e.z.literal("S256")}),_=e.z.object({deep_link:e.z.string(),polling_code:e.z.string(),expired_at:e.z.number()}),I=e.z.object({polling_code:e.z.string()}),Y=["pending","authorized","rejected","expired"],H=e.z.enum(Y),k=e.z.object({status:H,authorization_code:e.z.optional(e.z.string())}),E=e.z.object({authorization_code:e.z.string(),code_verifier:e.z.string()}),w=e.z.object({access_token:e.z.string()}),B=e.z.object({access_token:e.z.string()}),j=e.z.object({is_valid:e.z.boolean(),access_token:e.z.optional(e.z.string())}),T=e.z.object({app_callback_session_address:e.z.string(),expired_at:e.z.number(),issued_at:e.z.number()});function Q(a){return btoa(a).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function P(a){let s=a.replace(/-/g,"+").replace(/_/g,"/");for(;s.length%4;)s+="=";return atob(s)}const Z="https://sso.alien.com",ee=5e3,f="alien-sso_",S=(a,s)=>new URL(s,a).toString(),v=e.z.object({ssoBaseUrl:e.z.url(),providerAddress:e.z.string(),pollingInterval:e.z.optional(e.z.number())});class se{constructor(s){this.config=v.parse(s),this.ssoBaseUrl=this.config.ssoBaseUrl||Z,this.providerAddress=this.config.providerAddress,this.pollingInterval=this.config.pollingInterval||ee}generateCodeVerifier(s=128){let t;const o=typeof window!="undefined"&&window.crypto;if(o&&o.getRandomValues)t=new Uint8Array(s),o.getRandomValues(t);else{t=new Uint8Array(s);for(let r=0;r<s;r++)t[r]=Math.floor(Math.random()*256)}let n="";for(let r=0;r<t.length;r++)n+=String.fromCharCode(t[r]);return Q(n)}generateCodeChallenge(s){return $.sha256(s)}generateDeeplink(){return g(this,null,function*(){const s=this.generateCodeVerifier(),t=this.generateCodeChallenge(s);sessionStorage.setItem(f+"code_verifier",s);const o=`${this.config.ssoBaseUrl}/sso/authorize`,n={code_challenge:t,code_challenge_method:"S256"};R.parse(n);const c=yield(yield fetch(o,{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(n)})).json();return _.parse(c)})}pollAuth(s){return g(this,null,function*(){const t={polling_code:s};I.parse(t);const o=yield fetch(S(this.config.ssoBaseUrl,"/sso/poll"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(t)});if(!o.ok)throw new Error(`Poll failed: ${o.statusText}`);const n=yield o.json();return k.parse(n)})}exchangeToken(s){return g(this,null,function*(){const t=sessionStorage.getItem(f+"code_verifier");if(!t)throw new Error("Missing code verifier.");const o={authorization_code:s,code_verifier:t};E.parse(o);const n=yield fetch(S(this.config.ssoBaseUrl,"/sso/access_token/exchange"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(o)});if(!n.ok)throw new Error(`ExchangeCode failed: ${n.statusText}`);const r=yield n.json(),c=w.parse(r);if(c.access_token)return localStorage.setItem(f+"access_token",c.access_token),c.access_token;throw new Error("Exchange failed")})}verifyAuth(){return g(this,null,function*(){const s=this.getAccessToken();if(!s)return!1;const t={access_token:s};B.parse(t);const o=yield fetch(S(this.config.ssoBaseUrl,"/sso/access_token/verify"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(t)});if(!o.ok)return!1;const n=yield o.json(),r=j.parse(n);return r.access_token&&localStorage.setItem(f+"access_token",r.access_token),r.is_valid})}getAccessToken(){return localStorage.getItem(f+"access_token")}getAuthData(){const s=this.getAccessToken();if(!s)return null;const t=s.split(".");if(t.length!==3)return null;let o;try{const r=P(t[0]);o=JSON.parse(r)}catch(r){return null}if(o.alg!=="HS256"||o.typ!=="JWT")return null;let n;try{const r=JSON.parse(P(t[1]));n=T.parse(r)}catch(r){return null}return n}logout(){localStorage.removeItem(f+"access_token"),sessionStorage.removeItem(f+"code_verifier")}}const C=e.z.object({solana_address:e.z.string()}),D=e.z.object({deep_link:e.z.string(),polling_code:e.z.string(),expired_at:e.z.number()}),O=e.z.object({polling_code:e.z.string()}),te=["pending","authorized","rejected","expired"],oe=e.z.enum(te),U=e.z.object({status:oe,oracle_signature:e.z.optional(e.z.string()),oracle_public_key:e.z.optional(e.z.string()),solana_address:e.z.optional(e.z.string()),timestamp:e.z.optional(e.z.number()),session_address:e.z.optional(e.z.string())}),L=e.z.object({solana_address:e.z.string()}),x=e.z.object({session_address:e.z.string()});function ne(a){return i.PublicKey.findProgramAddressSync([Buffer.from("program_state")],a)}function re(a){return i.PublicKey.findProgramAddressSync([Buffer.from("credential_signer")],a)}function ae(a){return i.PublicKey.findProgramAddressSync([Buffer.from("session_registry")],a)}function ie(a,s){return i.PublicKey.findProgramAddressSync([Buffer.from("session"),Buffer.from(a)],s)}function ce(a,s){return i.PublicKey.findProgramAddressSync([Buffer.from("solana"),a.toBuffer()],s)}function le(a,s,t,o){return i.PublicKey.findProgramAddressSync([Buffer.from("attestation"),a.toBuffer(),s.toBuffer(),t.toBuffer()],o)}const de="https://sso.alien.com",ge=5e3,ue="9cstDz8WWRAFaq1vVpTjfHz6tjgh6SJaqYFeZWi1pFHG",fe="DeHa6pyZ2CFSbQQiNMm7FgoCXqmkX6tXG77C4Qycpta6",pe="22zoJMtdu4tQc2PzL74ZUT7FrwgB1Udec8DdW4yw4BdG",m=(a,s)=>new URL(s,a).toString(),V=e.z.object({ssoBaseUrl:e.z.url(),providerAddress:e.z.string(),pollingInterval:e.z.optional(e.z.number()),credentialSignerProgramId:e.z.optional(e.z.string()),sasProgramId:e.z.optional(e.z.string()),sessionRegistryProgramId:e.z.optional(e.z.string()),credentialAuthority:e.z.optional(e.z.string()),credentialName:e.z.optional(e.z.string()),schemaName:e.z.optional(e.z.string()),schemaVersion:e.z.optional(e.z.number())});class he{constructor(s){this.config=V.parse(s),this.ssoBaseUrl=this.config.ssoBaseUrl||de,this.providerAddress=this.config.providerAddress,this.pollingInterval=this.config.pollingInterval||ge,this.credentialSignerProgramId=new i.PublicKey(this.config.credentialSignerProgramId||ue),this.sasProgramId=new i.PublicKey(this.config.sasProgramId||pe),this.sessionRegistryProgramId=new i.PublicKey(this.config.sessionRegistryProgramId||fe)}generateDeeplink(s){return g(this,null,function*(){const t={solana_address:s};C.parse(t);const o=m(this.config.ssoBaseUrl,"/solana/link"),n=yield fetch(o,{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(t)});if(!n.ok)throw new Error(`GenerateLinkDeeplink failed: ${n.statusText}`);const r=yield n.json();return D.parse(r)})}pollAuth(s){return g(this,null,function*(){const t={polling_code:s};O.parse(t);const o=yield fetch(m(this.config.ssoBaseUrl,"/solana/poll"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(t)});if(!o.ok)throw new Error(`Poll failed: ${o.statusText}`);const n=yield o.json();return U.parse(n)})}getAttestation(s){return g(this,null,function*(){const t={solana_address:s};L.parse(t);const o=yield fetch(m(this.config.ssoBaseUrl,"/solana/attestation"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(t)});if(o.status===404)return null;if(!o.ok)throw new Error(`GetAttestation failed: ${o.statusText}`);const n=yield o.json();return x.parse(n).session_address})}buildCreateAttestationTransaction(s){return g(this,null,function*(){const{connection:t,payerPublicKey:o,sessionAddress:n,oracleSignature:r,oraclePublicKey:c,timestamp:u,expiry:l}=s,[d]=ne(this.credentialSignerProgramId),p=yield t.getAccountInfo(d);if(!p)throw new Error("ProgramState account not found");const y=p.data,z=new i.PublicKey(y.slice(40,72)),b=new i.PublicKey(y.slice(72,104)),[N]=re(this.credentialSignerProgramId),[q]=ae(this.sessionRegistryProgramId),[W]=ie(n,this.sessionRegistryProgramId),[K]=ce(o,this.sessionRegistryProgramId),[J]=le(z,b,o,this.sasProgramId),A=Buffer.alloc(8);A.writeBigInt64LE(BigInt(u));const G=Buffer.concat([Buffer.from(n),Buffer.from(o.toBase58()),A]),M=i.Ed25519Program.createInstructionWithPublicKey({publicKey:c.toBytes(),message:G,signature:r}),X=this.serializeCreateAttestationInstruction(n,Array.from(r),l,u),F=new i.TransactionInstruction({keys:[{pubkey:d,isSigner:!1,isWritable:!1},{pubkey:N,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!0,isWritable:!0},{pubkey:z,isSigner:!1,isWritable:!1},{pubkey:b,isSigner:!1,isWritable:!1},{pubkey:J,isSigner:!1,isWritable:!0},{pubkey:i.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:this.sasProgramId,isSigner:!1,isWritable:!1},{pubkey:i.SYSVAR_INSTRUCTIONS_PUBKEY,isSigner:!1,isWritable:!1},{pubkey:this.sessionRegistryProgramId,isSigner:!1,isWritable:!1},{pubkey:q,isSigner:!1,isWritable:!0},{pubkey:W,isSigner:!1,isWritable:!0},{pubkey:K,isSigner:!1,isWritable:!0}],programId:this.credentialSignerProgramId,data:X}),h=new i.Transaction;return h.add(M),h.add(F),h})}serializeCreateAttestationInstruction(s,t,o,n){const r=Buffer.from([49,24,67,80,12,249,96,239]),c=Buffer.alloc(4);c.writeUInt32LE(s.length);const u=Buffer.from(s),l=Buffer.from(t),d=Buffer.alloc(8);d.writeBigInt64LE(BigInt(o));const p=Buffer.alloc(8);return p.writeBigInt64LE(BigInt(n)),Buffer.concat([r,c,u,l,d,p])}}exports.AlienSolanaSsoClient=he;exports.AlienSolanaSsoClientSchema=V;exports.AlienSsoClient=se;exports.AlienSsoClientSchema=v;exports.AuthorizeRequestSchema=R;exports.AuthorizeResponseSchema=_;exports.ExchangeCodeRequestSchema=E;exports.ExchangeCodeResponseSchema=w;exports.PollRequestSchema=I;exports.PollResponseSchema=k;exports.SolanaAttestationRequestSchema=L;exports.SolanaAttestationResponseSchema=x;exports.SolanaLinkRequestSchema=C;exports.SolanaLinkResponseSchema=D;exports.SolanaPollRequestSchema=O;exports.SolanaPollResponseSchema=U;exports.TokenInfoSchema=T;exports.VerifyTokenRequestSchema=B;exports.VerifyTokenResponseSchema=j;
1
+ "use strict";var d=(a,o,s)=>new Promise((n,r)=>{var t=i=>{try{h(s.next(i))}catch(g){r(g)}},c=i=>{try{h(s.throw(i))}catch(g){r(g)}},h=i=>i.done?n(i.value):Promise.resolve(i.value).then(t,c);h((s=s.apply(a,o)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("zod/v4-mini"),j=require("js-sha256"),S=e.z.object({code_challenge:e.z.string(),code_challenge_method:e.z.literal("S256")}),f=e.z.object({deep_link:e.z.string(),polling_code:e.z.string(),expired_at:e.z.number()}),_=e.z.object({polling_code:e.z.string()}),v=["pending","authorized","rejected","expired"],T=e.z.enum(v),m=e.z.object({status:T,authorization_code:e.z.optional(e.z.string())}),z=e.z.object({authorization_code:e.z.string(),code_verifier:e.z.string()}),y=e.z.object({access_token:e.z.string()}),R=e.z.object({access_token:e.z.string()}),k=e.z.object({is_valid:e.z.boolean(),access_token:e.z.optional(e.z.string())}),b=e.z.object({app_callback_session_address:e.z.string(),expired_at:e.z.number(),issued_at:e.z.number()});function w(a){return btoa(a).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function u(a){let o=a.replace(/-/g,"+").replace(/_/g,"/");for(;o.length%4;)o+="=";return atob(o)}const C="https://sso.alien.com",E=5e3,l="alien-sso_",p=(a,o)=>new URL(o,a).toString(),A=e.z.object({ssoBaseUrl:e.z.url(),providerAddress:e.z.string(),pollingInterval:e.z.optional(e.z.number())});class P{constructor(o){this.config=A.parse(o),this.ssoBaseUrl=this.config.ssoBaseUrl||C,this.providerAddress=this.config.providerAddress,this.pollingInterval=this.config.pollingInterval||E}generateCodeVerifier(o=128){let s;const n=typeof window!="undefined"&&window.crypto;if(n&&n.getRandomValues)s=new Uint8Array(o),n.getRandomValues(s);else{s=new Uint8Array(o);for(let t=0;t<o;t++)s[t]=Math.floor(Math.random()*256)}let r="";for(let t=0;t<s.length;t++)r+=String.fromCharCode(s[t]);return w(r)}generateCodeChallenge(o){return j.sha256(o)}generateDeeplink(){return d(this,null,function*(){const o=this.generateCodeVerifier(),s=this.generateCodeChallenge(o);sessionStorage.setItem(l+"code_verifier",o);const n=`${this.config.ssoBaseUrl}/sso/authorize`,r={code_challenge:s,code_challenge_method:"S256"};S.parse(r);const c=yield(yield fetch(n,{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(r)})).json();return f.parse(c)})}pollAuth(o){return d(this,null,function*(){const s={polling_code:o};_.parse(s);const n=yield fetch(p(this.config.ssoBaseUrl,"/sso/poll"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(s)});if(!n.ok)throw new Error(`Poll failed: ${n.statusText}`);const r=yield n.json();return m.parse(r)})}exchangeToken(o){return d(this,null,function*(){const s=sessionStorage.getItem(l+"code_verifier");if(!s)throw new Error("Missing code verifier.");const n={authorization_code:o,code_verifier:s};z.parse(n);const r=yield fetch(p(this.config.ssoBaseUrl,"/sso/access_token/exchange"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(n)});if(!r.ok)throw new Error(`ExchangeCode failed: ${r.statusText}`);const t=yield r.json(),c=y.parse(t);if(c.access_token)return localStorage.setItem(l+"access_token",c.access_token),c.access_token;throw new Error("Exchange failed")})}verifyAuth(){return d(this,null,function*(){const o=this.getAccessToken();if(!o)return!1;const s={access_token:o};R.parse(s);const n=yield fetch(p(this.config.ssoBaseUrl,"/sso/access_token/verify"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(s)});if(!n.ok)return!1;const r=yield n.json(),t=k.parse(r);return t.access_token&&localStorage.setItem(l+"access_token",t.access_token),t.is_valid})}getAccessToken(){return localStorage.getItem(l+"access_token")}getAuthData(){const o=this.getAccessToken();if(!o)return null;const s=o.split(".");if(s.length!==3)return null;let n;try{const t=u(s[0]);n=JSON.parse(t)}catch(t){return null}if(n.alg!=="HS256"||n.typ!=="JWT")return null;let r;try{const t=JSON.parse(u(s[1]));r=b.parse(t)}catch(t){return null}return r}logout(){localStorage.removeItem(l+"access_token"),sessionStorage.removeItem(l+"code_verifier")}}exports.AlienSsoClient=P;exports.AlienSsoClientSchema=A;exports.AuthorizeRequestSchema=S;exports.AuthorizeResponseSchema=f;exports.ExchangeCodeRequestSchema=z;exports.ExchangeCodeResponseSchema=y;exports.PollRequestSchema=_;exports.PollResponseSchema=m;exports.TokenInfoSchema=b;exports.VerifyTokenRequestSchema=R;exports.VerifyTokenResponseSchema=k;
package/dist/index.d.ts CHANGED
@@ -1,47 +1,5 @@
1
- import { Connection } from '@solana/web3.js';
2
- import { PublicKey } from '@solana/web3.js';
3
- import { Transaction } from '@solana/web3.js';
4
1
  import { z } from 'zod/v4-mini';
5
2
 
6
- export declare class AlienSolanaSsoClient {
7
- readonly config: AlienSolanaSsoClientConfig;
8
- readonly pollingInterval: number;
9
- readonly ssoBaseUrl: string;
10
- readonly providerAddress: string;
11
- readonly credentialSignerProgramId: PublicKey;
12
- readonly sasProgramId: PublicKey;
13
- readonly sessionRegistryProgramId: PublicKey;
14
- constructor(config: AlienSolanaSsoClientConfig);
15
- generateDeeplink(solanaAddress: string): Promise<SolanaLinkResponse>;
16
- pollAuth(pollingCode: string): Promise<SolanaPollResponse>;
17
- getAttestation(solanaAddress: string): Promise<string | null>;
18
- buildCreateAttestationTransaction(params: {
19
- connection: Connection;
20
- payerPublicKey: PublicKey;
21
- sessionAddress: string;
22
- oracleSignature: Uint8Array;
23
- oraclePublicKey: PublicKey;
24
- timestamp: number;
25
- expiry: number;
26
- }): Promise<Transaction>;
27
- private serializeCreateAttestationInstruction;
28
- }
29
-
30
- export declare type AlienSolanaSsoClientConfig = z.infer<typeof AlienSolanaSsoClientSchema>;
31
-
32
- export declare const AlienSolanaSsoClientSchema: z.ZodMiniObject<{
33
- ssoBaseUrl: z.ZodMiniURL;
34
- providerAddress: z.ZodMiniString<string>;
35
- pollingInterval: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
36
- credentialSignerProgramId: z.ZodMiniOptional<z.ZodMiniString<string>>;
37
- sasProgramId: z.ZodMiniOptional<z.ZodMiniString<string>>;
38
- sessionRegistryProgramId: z.ZodMiniOptional<z.ZodMiniString<string>>;
39
- credentialAuthority: z.ZodMiniOptional<z.ZodMiniString<string>>;
40
- credentialName: z.ZodMiniOptional<z.ZodMiniString<string>>;
41
- schemaName: z.ZodMiniOptional<z.ZodMiniString<string>>;
42
- schemaVersion: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
43
- }, z.core.$strip>;
44
-
45
3
  export declare class AlienSsoClient {
46
4
  readonly config: AlienSsoClientConfig;
47
5
  readonly pollingInterval: number;
@@ -127,63 +85,6 @@ export declare const PollResponseSchema: z.ZodMiniObject<{
127
85
  authorization_code: z.ZodMiniOptional<z.ZodMiniString<string>>;
128
86
  }, z.core.$strip>;
129
87
 
130
- export declare type SolanaAttestationRequest = z.infer<typeof SolanaAttestationRequestSchema>;
131
-
132
- /**
133
- * Solana Attestation request/response schema
134
- */
135
- export declare const SolanaAttestationRequestSchema: z.ZodMiniObject<{
136
- solana_address: z.ZodMiniString<string>;
137
- }, z.core.$strip>;
138
-
139
- export declare type SolanaAttestationResponse = z.infer<typeof SolanaAttestationResponseSchema>;
140
-
141
- export declare const SolanaAttestationResponseSchema: z.ZodMiniObject<{
142
- session_address: z.ZodMiniString<string>;
143
- }, z.core.$strip>;
144
-
145
- export declare type SolanaLinkRequest = z.infer<typeof SolanaLinkRequestSchema>;
146
-
147
- /**
148
- * Solana Link request/response schema
149
- */
150
- export declare const SolanaLinkRequestSchema: z.ZodMiniObject<{
151
- solana_address: z.ZodMiniString<string>;
152
- }, z.core.$strip>;
153
-
154
- export declare type SolanaLinkResponse = z.infer<typeof SolanaLinkResponseSchema>;
155
-
156
- export declare const SolanaLinkResponseSchema: z.ZodMiniObject<{
157
- deep_link: z.ZodMiniString<string>;
158
- polling_code: z.ZodMiniString<string>;
159
- expired_at: z.ZodMiniNumber<number>;
160
- }, z.core.$strip>;
161
-
162
- export declare type SolanaPollRequest = z.infer<typeof SolanaPollRequestSchema>;
163
-
164
- /**
165
- * Solana Poll request/response schema
166
- */
167
- export declare const SolanaPollRequestSchema: z.ZodMiniObject<{
168
- polling_code: z.ZodMiniString<string>;
169
- }, z.core.$strip>;
170
-
171
- export declare type SolanaPollResponse = z.infer<typeof SolanaPollResponseSchema>;
172
-
173
- export declare const SolanaPollResponseSchema: z.ZodMiniObject<{
174
- status: z.ZodMiniEnum<{
175
- pending: "pending";
176
- authorized: "authorized";
177
- rejected: "rejected";
178
- expired: "expired";
179
- }>;
180
- oracle_signature: z.ZodMiniOptional<z.ZodMiniString<string>>;
181
- oracle_public_key: z.ZodMiniOptional<z.ZodMiniString<string>>;
182
- solana_address: z.ZodMiniOptional<z.ZodMiniString<string>>;
183
- timestamp: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
184
- session_address: z.ZodMiniOptional<z.ZodMiniString<string>>;
185
- }, z.core.$strip>;
186
-
187
88
  export declare type TokenInfo = z.infer<typeof TokenInfoSchema>;
188
89
 
189
90
  /**
package/dist/index.esm.js CHANGED
@@ -1,465 +1,225 @@
1
- var g = (a, s, t) => new Promise((o, n) => {
2
- var r = (c) => {
1
+ var d = (a, o, s) => new Promise((n, r) => {
2
+ var t = (i) => {
3
3
  try {
4
- f(t.next(c));
5
- } catch (d) {
6
- n(d);
4
+ h(s.next(i));
5
+ } catch (p) {
6
+ r(p);
7
7
  }
8
- }, i = (c) => {
8
+ }, c = (i) => {
9
9
  try {
10
- f(t.throw(c));
11
- } catch (d) {
12
- n(d);
10
+ h(s.throw(i));
11
+ } catch (p) {
12
+ r(p);
13
13
  }
14
- }, f = (c) => c.done ? o(c.value) : Promise.resolve(c.value).then(r, i);
15
- f((t = t.apply(a, s)).next());
14
+ }, h = (i) => i.done ? n(i.value) : Promise.resolve(i.value).then(t, c);
15
+ h((s = s.apply(a, o)).next());
16
16
  });
17
17
  import { z as e } from "zod/v4-mini";
18
- import { sha256 as D } from "js-sha256";
19
- import { PublicKey as l, Ed25519Program as C, TransactionInstruction as O, SystemProgram as U, SYSVAR_INSTRUCTIONS_PUBKEY as L, Transaction as x } from "@solana/web3.js";
20
- const N = e.object({
18
+ import { sha256 as f } from "js-sha256";
19
+ const _ = e.object({
21
20
  code_challenge: e.string(),
22
21
  code_challenge_method: e.literal("S256")
23
- }), V = e.object({
22
+ }), S = e.object({
24
23
  deep_link: e.string(),
25
24
  polling_code: e.string(),
26
25
  expired_at: e.number()
27
- }), W = e.object({
26
+ }), m = e.object({
28
27
  polling_code: e.string()
29
- }), z = ["pending", "authorized", "rejected", "expired"], J = e.enum(z), G = e.object({
30
- status: J,
28
+ }), y = ["pending", "authorized", "rejected", "expired"], k = e.enum(y), b = e.object({
29
+ status: k,
31
30
  authorization_code: e.optional(e.string())
32
- }), q = e.object({
31
+ }), R = e.object({
33
32
  authorization_code: e.string(),
34
33
  code_verifier: e.string()
35
- }), X = e.object({
34
+ }), A = e.object({
36
35
  access_token: e.string()
37
- }), F = e.object({
36
+ }), j = e.object({
38
37
  access_token: e.string()
39
- }), M = e.object({
38
+ }), v = e.object({
40
39
  is_valid: e.boolean(),
41
40
  access_token: e.optional(e.string())
42
- }), $ = e.object({
41
+ }), w = e.object({
43
42
  app_callback_session_address: e.string(),
44
43
  expired_at: e.number(),
45
44
  issued_at: e.number()
46
45
  });
47
- function K(a) {
46
+ function E(a) {
48
47
  return btoa(a).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
49
48
  }
50
- function P(a) {
51
- let s = a.replace(/-/g, "+").replace(/_/g, "/");
52
- for (; s.length % 4; )
53
- s += "=";
54
- return atob(s);
49
+ function u(a) {
50
+ let o = a.replace(/-/g, "+").replace(/_/g, "/");
51
+ for (; o.length % 4; )
52
+ o += "=";
53
+ return atob(o);
55
54
  }
56
- const Y = "https://sso.alien.com", H = 5e3, p = "alien-sso_", S = (a, s) => new URL(s, a).toString(), Q = e.object({
55
+ const T = "https://sso.alien.com", C = 5e3, l = "alien-sso_", g = (a, o) => new URL(o, a).toString(), O = e.object({
57
56
  ssoBaseUrl: e.url(),
58
57
  providerAddress: e.string(),
59
58
  pollingInterval: e.optional(e.number())
60
59
  });
61
- class Re {
62
- constructor(s) {
63
- this.config = Q.parse(s), this.ssoBaseUrl = this.config.ssoBaseUrl || Y, this.providerAddress = this.config.providerAddress, this.pollingInterval = this.config.pollingInterval || H;
64
- }
65
- generateCodeVerifier(s = 128) {
66
- let t;
67
- const o = typeof window != "undefined" && window.crypto;
68
- if (o && o.getRandomValues)
69
- t = new Uint8Array(s), o.getRandomValues(t);
60
+ class x {
61
+ constructor(o) {
62
+ this.config = O.parse(o), this.ssoBaseUrl = this.config.ssoBaseUrl || T, this.providerAddress = this.config.providerAddress, this.pollingInterval = this.config.pollingInterval || C;
63
+ }
64
+ generateCodeVerifier(o = 128) {
65
+ let s;
66
+ const n = typeof window != "undefined" && window.crypto;
67
+ if (n && n.getRandomValues)
68
+ s = new Uint8Array(o), n.getRandomValues(s);
70
69
  else {
71
- t = new Uint8Array(s);
72
- for (let r = 0; r < s; r++)
73
- t[r] = Math.floor(Math.random() * 256);
70
+ s = new Uint8Array(o);
71
+ for (let t = 0; t < o; t++)
72
+ s[t] = Math.floor(Math.random() * 256);
74
73
  }
75
- let n = "";
76
- for (let r = 0; r < t.length; r++)
77
- n += String.fromCharCode(t[r]);
78
- return K(n);
74
+ let r = "";
75
+ for (let t = 0; t < s.length; t++)
76
+ r += String.fromCharCode(s[t]);
77
+ return E(r);
79
78
  }
80
- generateCodeChallenge(s) {
81
- return D(s);
79
+ generateCodeChallenge(o) {
80
+ return f(o);
82
81
  }
83
82
  generateDeeplink() {
84
- return g(this, null, function* () {
85
- const s = this.generateCodeVerifier(), t = this.generateCodeChallenge(s);
86
- sessionStorage.setItem(p + "code_verifier", s);
87
- const o = `${this.config.ssoBaseUrl}/sso/authorize`, n = {
88
- code_challenge: t,
83
+ return d(this, null, function* () {
84
+ const o = this.generateCodeVerifier(), s = this.generateCodeChallenge(o);
85
+ sessionStorage.setItem(l + "code_verifier", o);
86
+ const n = `${this.config.ssoBaseUrl}/sso/authorize`, r = {
87
+ code_challenge: s,
89
88
  code_challenge_method: "S256"
90
89
  };
91
- N.parse(n);
92
- const i = yield (yield fetch(o, {
90
+ _.parse(r);
91
+ const c = yield (yield fetch(n, {
93
92
  method: "POST",
94
93
  headers: {
95
94
  "Content-Type": "application/json",
96
95
  "X-PROVIDER-ADDRESS": this.providerAddress
97
96
  },
98
- body: JSON.stringify(n)
97
+ body: JSON.stringify(r)
99
98
  })).json();
100
- return V.parse(i);
99
+ return S.parse(c);
101
100
  });
102
101
  }
103
- pollAuth(s) {
104
- return g(this, null, function* () {
105
- const t = {
106
- polling_code: s
102
+ pollAuth(o) {
103
+ return d(this, null, function* () {
104
+ const s = {
105
+ polling_code: o
107
106
  };
108
- W.parse(t);
109
- const o = yield fetch(S(this.config.ssoBaseUrl, "/sso/poll"), {
107
+ m.parse(s);
108
+ const n = yield fetch(g(this.config.ssoBaseUrl, "/sso/poll"), {
110
109
  method: "POST",
111
110
  headers: {
112
111
  "Content-Type": "application/json",
113
112
  "X-PROVIDER-ADDRESS": this.providerAddress
114
113
  },
115
- body: JSON.stringify(t)
114
+ body: JSON.stringify(s)
116
115
  });
117
- if (!o.ok)
118
- throw new Error(`Poll failed: ${o.statusText}`);
119
- const n = yield o.json();
120
- return G.parse(n);
116
+ if (!n.ok)
117
+ throw new Error(`Poll failed: ${n.statusText}`);
118
+ const r = yield n.json();
119
+ return b.parse(r);
121
120
  });
122
121
  }
123
- exchangeToken(s) {
124
- return g(this, null, function* () {
125
- const t = sessionStorage.getItem(p + "code_verifier");
126
- if (!t) throw new Error("Missing code verifier.");
127
- const o = {
128
- authorization_code: s,
129
- code_verifier: t
122
+ exchangeToken(o) {
123
+ return d(this, null, function* () {
124
+ const s = sessionStorage.getItem(l + "code_verifier");
125
+ if (!s) throw new Error("Missing code verifier.");
126
+ const n = {
127
+ authorization_code: o,
128
+ code_verifier: s
130
129
  };
131
- q.parse(o);
132
- const n = yield fetch(
133
- S(this.config.ssoBaseUrl, "/sso/access_token/exchange"),
130
+ R.parse(n);
131
+ const r = yield fetch(
132
+ g(this.config.ssoBaseUrl, "/sso/access_token/exchange"),
134
133
  {
135
134
  method: "POST",
136
135
  headers: {
137
136
  "Content-Type": "application/json",
138
137
  "X-PROVIDER-ADDRESS": this.providerAddress
139
138
  },
140
- body: JSON.stringify(o)
139
+ body: JSON.stringify(n)
141
140
  }
142
141
  );
143
- if (!n.ok)
144
- throw new Error(`ExchangeCode failed: ${n.statusText}`);
145
- const r = yield n.json(), i = X.parse(r);
146
- if (i.access_token)
142
+ if (!r.ok)
143
+ throw new Error(`ExchangeCode failed: ${r.statusText}`);
144
+ const t = yield r.json(), c = A.parse(t);
145
+ if (c.access_token)
147
146
  return localStorage.setItem(
148
- p + "access_token",
149
- i.access_token
150
- ), i.access_token;
147
+ l + "access_token",
148
+ c.access_token
149
+ ), c.access_token;
151
150
  throw new Error("Exchange failed");
152
151
  });
153
152
  }
154
153
  verifyAuth() {
155
- return g(this, null, function* () {
156
- const s = this.getAccessToken();
157
- if (!s)
154
+ return d(this, null, function* () {
155
+ const o = this.getAccessToken();
156
+ if (!o)
158
157
  return !1;
159
- const t = {
160
- access_token: s
158
+ const s = {
159
+ access_token: o
161
160
  };
162
- F.parse(t);
163
- const o = yield fetch(
164
- S(this.config.ssoBaseUrl, "/sso/access_token/verify"),
161
+ j.parse(s);
162
+ const n = yield fetch(
163
+ g(this.config.ssoBaseUrl, "/sso/access_token/verify"),
165
164
  {
166
165
  method: "POST",
167
166
  headers: {
168
167
  "Content-Type": "application/json",
169
168
  "X-PROVIDER-ADDRESS": this.providerAddress
170
169
  },
171
- body: JSON.stringify(t)
170
+ body: JSON.stringify(s)
172
171
  }
173
172
  );
174
- if (!o.ok)
173
+ if (!n.ok)
175
174
  return !1;
176
- const n = yield o.json(), r = M.parse(n);
177
- return r.access_token && localStorage.setItem(
178
- p + "access_token",
179
- r.access_token
180
- ), r.is_valid;
175
+ const r = yield n.json(), t = v.parse(r);
176
+ return t.access_token && localStorage.setItem(
177
+ l + "access_token",
178
+ t.access_token
179
+ ), t.is_valid;
181
180
  });
182
181
  }
183
182
  getAccessToken() {
184
- return localStorage.getItem(p + "access_token");
183
+ return localStorage.getItem(l + "access_token");
185
184
  }
186
185
  getAuthData() {
187
- const s = this.getAccessToken();
188
- if (!s) return null;
189
- const t = s.split(".");
190
- if (t.length !== 3)
186
+ const o = this.getAccessToken();
187
+ if (!o) return null;
188
+ const s = o.split(".");
189
+ if (s.length !== 3)
191
190
  return null;
192
- let o;
191
+ let n;
193
192
  try {
194
- const r = P(t[0]);
195
- o = JSON.parse(r);
196
- } catch (r) {
193
+ const t = u(s[0]);
194
+ n = JSON.parse(t);
195
+ } catch (t) {
197
196
  return null;
198
197
  }
199
- if (o.alg !== "HS256" || o.typ !== "JWT")
198
+ if (n.alg !== "HS256" || n.typ !== "JWT")
200
199
  return null;
201
- let n;
200
+ let r;
202
201
  try {
203
- const r = JSON.parse(P(t[1]));
204
- n = $.parse(r);
205
- } catch (r) {
202
+ const t = JSON.parse(u(s[1]));
203
+ r = w.parse(t);
204
+ } catch (t) {
206
205
  return null;
207
206
  }
208
- return n;
207
+ return r;
209
208
  }
210
209
  logout() {
211
- localStorage.removeItem(p + "access_token"), sessionStorage.removeItem(p + "code_verifier");
212
- }
213
- }
214
- const Z = e.object({
215
- solana_address: e.string()
216
- }), ee = e.object({
217
- deep_link: e.string(),
218
- polling_code: e.string(),
219
- expired_at: e.number()
220
- }), se = e.object({
221
- polling_code: e.string()
222
- }), te = ["pending", "authorized", "rejected", "expired"], oe = e.enum(te), ne = e.object({
223
- status: oe,
224
- oracle_signature: e.optional(e.string()),
225
- oracle_public_key: e.optional(e.string()),
226
- solana_address: e.optional(e.string()),
227
- timestamp: e.optional(e.number()),
228
- session_address: e.optional(e.string())
229
- }), re = e.object({
230
- solana_address: e.string()
231
- }), ae = e.object({
232
- session_address: e.string()
233
- });
234
- function ie(a) {
235
- return l.findProgramAddressSync(
236
- [Buffer.from("program_state")],
237
- a
238
- );
239
- }
240
- function ce(a) {
241
- return l.findProgramAddressSync(
242
- [Buffer.from("credential_signer")],
243
- a
244
- );
245
- }
246
- function le(a) {
247
- return l.findProgramAddressSync(
248
- [Buffer.from("session_registry")],
249
- a
250
- );
251
- }
252
- function de(a, s) {
253
- return l.findProgramAddressSync(
254
- [Buffer.from("session"), Buffer.from(a)],
255
- s
256
- );
257
- }
258
- function ge(a, s) {
259
- return l.findProgramAddressSync(
260
- [Buffer.from("solana"), a.toBuffer()],
261
- s
262
- );
263
- }
264
- function fe(a, s, t, o) {
265
- return l.findProgramAddressSync(
266
- [
267
- Buffer.from("attestation"),
268
- a.toBuffer(),
269
- s.toBuffer(),
270
- t.toBuffer()
271
- ],
272
- o
273
- );
274
- }
275
- const pe = "https://sso.alien.com", ue = 5e3, he = "9cstDz8WWRAFaq1vVpTjfHz6tjgh6SJaqYFeZWi1pFHG", Se = "DeHa6pyZ2CFSbQQiNMm7FgoCXqmkX6tXG77C4Qycpta6", me = "22zoJMtdu4tQc2PzL74ZUT7FrwgB1Udec8DdW4yw4BdG", m = (a, s) => new URL(s, a).toString(), ye = e.object({
276
- ssoBaseUrl: e.url(),
277
- providerAddress: e.string(),
278
- pollingInterval: e.optional(e.number()),
279
- credentialSignerProgramId: e.optional(e.string()),
280
- sasProgramId: e.optional(e.string()),
281
- sessionRegistryProgramId: e.optional(e.string()),
282
- credentialAuthority: e.optional(e.string()),
283
- credentialName: e.optional(e.string()),
284
- schemaName: e.optional(e.string()),
285
- schemaVersion: e.optional(e.number())
286
- });
287
- class Ie {
288
- constructor(s) {
289
- this.config = ye.parse(s), this.ssoBaseUrl = this.config.ssoBaseUrl || pe, this.providerAddress = this.config.providerAddress, this.pollingInterval = this.config.pollingInterval || ue, this.credentialSignerProgramId = new l(
290
- this.config.credentialSignerProgramId || he
291
- ), this.sasProgramId = new l(
292
- this.config.sasProgramId || me
293
- ), this.sessionRegistryProgramId = new l(
294
- this.config.sessionRegistryProgramId || Se
295
- );
296
- }
297
- generateDeeplink(s) {
298
- return g(this, null, function* () {
299
- const t = {
300
- solana_address: s
301
- };
302
- Z.parse(t);
303
- const o = m(this.config.ssoBaseUrl, "/solana/link"), n = yield fetch(o, {
304
- method: "POST",
305
- headers: {
306
- "Content-Type": "application/json",
307
- "X-PROVIDER-ADDRESS": this.providerAddress
308
- },
309
- body: JSON.stringify(t)
310
- });
311
- if (!n.ok)
312
- throw new Error(`GenerateLinkDeeplink failed: ${n.statusText}`);
313
- const r = yield n.json();
314
- return ee.parse(r);
315
- });
316
- }
317
- pollAuth(s) {
318
- return g(this, null, function* () {
319
- const t = {
320
- polling_code: s
321
- };
322
- se.parse(t);
323
- const o = yield fetch(
324
- m(this.config.ssoBaseUrl, "/solana/poll"),
325
- {
326
- method: "POST",
327
- headers: {
328
- "Content-Type": "application/json",
329
- "X-PROVIDER-ADDRESS": this.providerAddress
330
- },
331
- body: JSON.stringify(t)
332
- }
333
- );
334
- if (!o.ok)
335
- throw new Error(`Poll failed: ${o.statusText}`);
336
- const n = yield o.json();
337
- return ne.parse(n);
338
- });
339
- }
340
- getAttestation(s) {
341
- return g(this, null, function* () {
342
- const t = {
343
- solana_address: s
344
- };
345
- re.parse(t);
346
- const o = yield fetch(
347
- m(this.config.ssoBaseUrl, "/solana/attestation"),
348
- {
349
- method: "POST",
350
- headers: {
351
- "Content-Type": "application/json",
352
- "X-PROVIDER-ADDRESS": this.providerAddress
353
- },
354
- body: JSON.stringify(t)
355
- }
356
- );
357
- if (o.status === 404)
358
- return null;
359
- if (!o.ok)
360
- throw new Error(`GetAttestation failed: ${o.statusText}`);
361
- const n = yield o.json();
362
- return ae.parse(n).session_address;
363
- });
364
- }
365
- buildCreateAttestationTransaction(s) {
366
- return g(this, null, function* () {
367
- const {
368
- connection: t,
369
- payerPublicKey: o,
370
- sessionAddress: n,
371
- oracleSignature: r,
372
- oraclePublicKey: i,
373
- timestamp: f,
374
- expiry: c
375
- } = s, [d] = ie(this.credentialSignerProgramId), u = yield t.getAccountInfo(d);
376
- if (!u)
377
- throw new Error("ProgramState account not found");
378
- const y = u.data, _ = new l(y.slice(40, 72)), A = new l(y.slice(72, 104)), [R] = ce(this.credentialSignerProgramId), [I] = le(this.sessionRegistryProgramId), [k] = de(n, this.sessionRegistryProgramId), [w] = ge(o, this.sessionRegistryProgramId), [B] = fe(
379
- _,
380
- A,
381
- o,
382
- this.sasProgramId
383
- ), b = Buffer.alloc(8);
384
- b.writeBigInt64LE(BigInt(f));
385
- const E = Buffer.concat([
386
- Buffer.from(n),
387
- Buffer.from(o.toBase58()),
388
- b
389
- ]), j = C.createInstructionWithPublicKey({
390
- publicKey: i.toBytes(),
391
- message: E,
392
- signature: r
393
- }), T = this.serializeCreateAttestationInstruction(
394
- n,
395
- Array.from(r),
396
- c,
397
- f
398
- ), v = new O({
399
- keys: [
400
- { pubkey: d, isSigner: !1, isWritable: !1 },
401
- { pubkey: R, isSigner: !1, isWritable: !1 },
402
- { pubkey: o, isSigner: !0, isWritable: !0 },
403
- { pubkey: _, isSigner: !1, isWritable: !1 },
404
- { pubkey: A, isSigner: !1, isWritable: !1 },
405
- { pubkey: B, isSigner: !1, isWritable: !0 },
406
- { pubkey: U.programId, isSigner: !1, isWritable: !1 },
407
- { pubkey: this.sasProgramId, isSigner: !1, isWritable: !1 },
408
- { pubkey: L, isSigner: !1, isWritable: !1 },
409
- { pubkey: this.sessionRegistryProgramId, isSigner: !1, isWritable: !1 },
410
- { pubkey: I, isSigner: !1, isWritable: !0 },
411
- { pubkey: k, isSigner: !1, isWritable: !0 },
412
- { pubkey: w, isSigner: !1, isWritable: !0 }
413
- ],
414
- programId: this.credentialSignerProgramId,
415
- data: T
416
- }), h = new x();
417
- return h.add(j), h.add(v), h;
418
- });
419
- }
420
- serializeCreateAttestationInstruction(s, t, o, n) {
421
- const r = Buffer.from([
422
- 49,
423
- 24,
424
- 67,
425
- 80,
426
- 12,
427
- 249,
428
- 96,
429
- 239
430
- ]), i = Buffer.alloc(4);
431
- i.writeUInt32LE(s.length);
432
- const f = Buffer.from(s), c = Buffer.from(t), d = Buffer.alloc(8);
433
- d.writeBigInt64LE(BigInt(o));
434
- const u = Buffer.alloc(8);
435
- return u.writeBigInt64LE(BigInt(n)), Buffer.concat([
436
- r,
437
- i,
438
- f,
439
- c,
440
- d,
441
- u
442
- ]);
210
+ localStorage.removeItem(l + "access_token"), sessionStorage.removeItem(l + "code_verifier");
443
211
  }
444
212
  }
445
213
  export {
446
- Ie as AlienSolanaSsoClient,
447
- ye as AlienSolanaSsoClientSchema,
448
- Re as AlienSsoClient,
449
- Q as AlienSsoClientSchema,
450
- N as AuthorizeRequestSchema,
451
- V as AuthorizeResponseSchema,
452
- q as ExchangeCodeRequestSchema,
453
- X as ExchangeCodeResponseSchema,
454
- W as PollRequestSchema,
455
- G as PollResponseSchema,
456
- re as SolanaAttestationRequestSchema,
457
- ae as SolanaAttestationResponseSchema,
458
- Z as SolanaLinkRequestSchema,
459
- ee as SolanaLinkResponseSchema,
460
- se as SolanaPollRequestSchema,
461
- ne as SolanaPollResponseSchema,
462
- $ as TokenInfoSchema,
463
- F as VerifyTokenRequestSchema,
464
- M as VerifyTokenResponseSchema
214
+ x as AlienSsoClient,
215
+ O as AlienSsoClientSchema,
216
+ _ as AuthorizeRequestSchema,
217
+ S as AuthorizeResponseSchema,
218
+ R as ExchangeCodeRequestSchema,
219
+ A as ExchangeCodeResponseSchema,
220
+ m as PollRequestSchema,
221
+ b as PollResponseSchema,
222
+ w as TokenInfoSchema,
223
+ j as VerifyTokenRequestSchema,
224
+ v as VerifyTokenResponseSchema
465
225
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("zod/v4-mini"),require("js-sha256"),require("@solana/web3.js")):typeof define=="function"&&define.amd?define(["exports","zod/v4-mini","js-sha256","@solana/web3.js"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n.AlienSsoCore={},n.Zod,n.jsSha256,n.solanaWeb3))})(this,(function(n,e,f,c){"use strict";var g=(n,e,f)=>new Promise((c,S)=>{var z=d=>{try{p(f.next(d))}catch(h){S(h)}},A=d=>{try{p(f.throw(d))}catch(h){S(h)}},p=d=>d.done?c(d.value):Promise.resolve(d.value).then(z,A);p((f=f.apply(n,e)).next())});const S=e.z.object({code_challenge:e.z.string(),code_challenge_method:e.z.literal("S256")}),z=e.z.object({deep_link:e.z.string(),polling_code:e.z.string(),expired_at:e.z.number()}),A=e.z.object({polling_code:e.z.string()}),p=["pending","authorized","rejected","expired"],d=e.z.enum(p),h=e.z.object({status:d,authorization_code:e.z.optional(e.z.string())}),k=e.z.object({authorization_code:e.z.string(),code_verifier:e.z.string()}),E=e.z.object({access_token:e.z.string()}),B=e.z.object({access_token:e.z.string()}),T=e.z.object({is_valid:e.z.boolean(),access_token:e.z.optional(e.z.string())}),C=e.z.object({app_callback_session_address:e.z.string(),expired_at:e.z.number(),issued_at:e.z.number()});function X(i){return btoa(i).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function w(i){let s=i.replace(/-/g,"+").replace(/_/g,"/");for(;s.length%4;)s+="=";return atob(s)}const F="https://sso.alien.com",$=5e3,u="alien-sso_",R=(i,s)=>new URL(s,i).toString(),j=e.z.object({ssoBaseUrl:e.z.url(),providerAddress:e.z.string(),pollingInterval:e.z.optional(e.z.number())});class x{constructor(s){this.config=j.parse(s),this.ssoBaseUrl=this.config.ssoBaseUrl||F,this.providerAddress=this.config.providerAddress,this.pollingInterval=this.config.pollingInterval||$}generateCodeVerifier(s=128){let o;const t=typeof window!="undefined"&&window.crypto;if(t&&t.getRandomValues)o=new Uint8Array(s),t.getRandomValues(o);else{o=new Uint8Array(s);for(let a=0;a<s;a++)o[a]=Math.floor(Math.random()*256)}let r="";for(let a=0;a<o.length;a++)r+=String.fromCharCode(o[a]);return X(r)}generateCodeChallenge(s){return f.sha256(s)}generateDeeplink(){return g(this,null,function*(){const s=this.generateCodeVerifier(),o=this.generateCodeChallenge(s);sessionStorage.setItem(u+"code_verifier",s);const t=`${this.config.ssoBaseUrl}/sso/authorize`,r={code_challenge:o,code_challenge_method:"S256"};S.parse(r);const l=yield(yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(r)})).json();return z.parse(l)})}pollAuth(s){return g(this,null,function*(){const o={polling_code:s};A.parse(o);const t=yield fetch(R(this.config.ssoBaseUrl,"/sso/poll"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(o)});if(!t.ok)throw new Error(`Poll failed: ${t.statusText}`);const r=yield t.json();return h.parse(r)})}exchangeToken(s){return g(this,null,function*(){const o=sessionStorage.getItem(u+"code_verifier");if(!o)throw new Error("Missing code verifier.");const t={authorization_code:s,code_verifier:o};k.parse(t);const r=yield fetch(R(this.config.ssoBaseUrl,"/sso/access_token/exchange"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(t)});if(!r.ok)throw new Error(`ExchangeCode failed: ${r.statusText}`);const a=yield r.json(),l=E.parse(a);if(l.access_token)return localStorage.setItem(u+"access_token",l.access_token),l.access_token;throw new Error("Exchange failed")})}verifyAuth(){return g(this,null,function*(){const s=this.getAccessToken();if(!s)return!1;const o={access_token:s};B.parse(o);const t=yield fetch(R(this.config.ssoBaseUrl,"/sso/access_token/verify"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(o)});if(!t.ok)return!1;const r=yield t.json(),a=T.parse(r);return a.access_token&&localStorage.setItem(u+"access_token",a.access_token),a.is_valid})}getAccessToken(){return localStorage.getItem(u+"access_token")}getAuthData(){const s=this.getAccessToken();if(!s)return null;const o=s.split(".");if(o.length!==3)return null;let t;try{const a=w(o[0]);t=JSON.parse(a)}catch(a){return null}if(t.alg!=="HS256"||t.typ!=="JWT")return null;let r;try{const a=JSON.parse(w(o[1]));r=C.parse(a)}catch(a){return null}return r}logout(){localStorage.removeItem(u+"access_token"),sessionStorage.removeItem(u+"code_verifier")}}const D=e.z.object({solana_address:e.z.string()}),O=e.z.object({deep_link:e.z.string(),polling_code:e.z.string(),expired_at:e.z.number()}),U=e.z.object({polling_code:e.z.string()}),Y=["pending","authorized","rejected","expired"],H=e.z.enum(Y),L=e.z.object({status:H,oracle_signature:e.z.optional(e.z.string()),oracle_public_key:e.z.optional(e.z.string()),solana_address:e.z.optional(e.z.string()),timestamp:e.z.optional(e.z.number()),session_address:e.z.optional(e.z.string())}),V=e.z.object({solana_address:e.z.string()}),N=e.z.object({session_address:e.z.string()});function Q(i){return c.PublicKey.findProgramAddressSync([Buffer.from("program_state")],i)}function Z(i){return c.PublicKey.findProgramAddressSync([Buffer.from("credential_signer")],i)}function v(i){return c.PublicKey.findProgramAddressSync([Buffer.from("session_registry")],i)}function M(i,s){return c.PublicKey.findProgramAddressSync([Buffer.from("session"),Buffer.from(i)],s)}function ee(i,s){return c.PublicKey.findProgramAddressSync([Buffer.from("solana"),i.toBuffer()],s)}function se(i,s,o,t){return c.PublicKey.findProgramAddressSync([Buffer.from("attestation"),i.toBuffer(),s.toBuffer(),o.toBuffer()],t)}const te="https://sso.alien.com",oe=5e3,re="9cstDz8WWRAFaq1vVpTjfHz6tjgh6SJaqYFeZWi1pFHG",ne="DeHa6pyZ2CFSbQQiNMm7FgoCXqmkX6tXG77C4Qycpta6",ae="22zoJMtdu4tQc2PzL74ZUT7FrwgB1Udec8DdW4yw4BdG",b=(i,s)=>new URL(s,i).toString(),q=e.z.object({ssoBaseUrl:e.z.url(),providerAddress:e.z.string(),pollingInterval:e.z.optional(e.z.number()),credentialSignerProgramId:e.z.optional(e.z.string()),sasProgramId:e.z.optional(e.z.string()),sessionRegistryProgramId:e.z.optional(e.z.string()),credentialAuthority:e.z.optional(e.z.string()),credentialName:e.z.optional(e.z.string()),schemaName:e.z.optional(e.z.string()),schemaVersion:e.z.optional(e.z.number())});class ie{constructor(s){this.config=q.parse(s),this.ssoBaseUrl=this.config.ssoBaseUrl||te,this.providerAddress=this.config.providerAddress,this.pollingInterval=this.config.pollingInterval||oe,this.credentialSignerProgramId=new c.PublicKey(this.config.credentialSignerProgramId||re),this.sasProgramId=new c.PublicKey(this.config.sasProgramId||ae),this.sessionRegistryProgramId=new c.PublicKey(this.config.sessionRegistryProgramId||ne)}generateDeeplink(s){return g(this,null,function*(){const o={solana_address:s};D.parse(o);const t=b(this.config.ssoBaseUrl,"/solana/link"),r=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(o)});if(!r.ok)throw new Error(`GenerateLinkDeeplink failed: ${r.statusText}`);const a=yield r.json();return O.parse(a)})}pollAuth(s){return g(this,null,function*(){const o={polling_code:s};U.parse(o);const t=yield fetch(b(this.config.ssoBaseUrl,"/solana/poll"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(o)});if(!t.ok)throw new Error(`Poll failed: ${t.statusText}`);const r=yield t.json();return L.parse(r)})}getAttestation(s){return g(this,null,function*(){const o={solana_address:s};V.parse(o);const t=yield fetch(b(this.config.ssoBaseUrl,"/solana/attestation"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(o)});if(t.status===404)return null;if(!t.ok)throw new Error(`GetAttestation failed: ${t.statusText}`);const r=yield t.json();return N.parse(r).session_address})}buildCreateAttestationTransaction(s){return g(this,null,function*(){const{connection:o,payerPublicKey:t,sessionAddress:r,oracleSignature:a,oraclePublicKey:l,timestamp:P,expiry:I}=s,[m]=Q(this.credentialSignerProgramId),y=yield o.getAccountInfo(m);if(!y)throw new Error("ProgramState account not found");const W=y.data,K=new c.PublicKey(W.slice(40,72)),J=new c.PublicKey(W.slice(72,104)),[ce]=Z(this.credentialSignerProgramId),[le]=v(this.sessionRegistryProgramId),[de]=M(r,this.sessionRegistryProgramId),[ge]=ee(t,this.sessionRegistryProgramId),[ue]=se(K,J,t,this.sasProgramId),G=Buffer.alloc(8);G.writeBigInt64LE(BigInt(P));const fe=Buffer.concat([Buffer.from(r),Buffer.from(t.toBase58()),G]),he=c.Ed25519Program.createInstructionWithPublicKey({publicKey:l.toBytes(),message:fe,signature:a}),Se=this.serializeCreateAttestationInstruction(r,Array.from(a),I,P),pe=new c.TransactionInstruction({keys:[{pubkey:m,isSigner:!1,isWritable:!1},{pubkey:ce,isSigner:!1,isWritable:!1},{pubkey:t,isSigner:!0,isWritable:!0},{pubkey:K,isSigner:!1,isWritable:!1},{pubkey:J,isSigner:!1,isWritable:!1},{pubkey:ue,isSigner:!1,isWritable:!0},{pubkey:c.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:this.sasProgramId,isSigner:!1,isWritable:!1},{pubkey:c.SYSVAR_INSTRUCTIONS_PUBKEY,isSigner:!1,isWritable:!1},{pubkey:this.sessionRegistryProgramId,isSigner:!1,isWritable:!1},{pubkey:le,isSigner:!1,isWritable:!0},{pubkey:de,isSigner:!1,isWritable:!0},{pubkey:ge,isSigner:!1,isWritable:!0}],programId:this.credentialSignerProgramId,data:Se}),_=new c.Transaction;return _.add(he),_.add(pe),_})}serializeCreateAttestationInstruction(s,o,t,r){const a=Buffer.from([49,24,67,80,12,249,96,239]),l=Buffer.alloc(4);l.writeUInt32LE(s.length);const P=Buffer.from(s),I=Buffer.from(o),m=Buffer.alloc(8);m.writeBigInt64LE(BigInt(t));const y=Buffer.alloc(8);return y.writeBigInt64LE(BigInt(r)),Buffer.concat([a,l,P,I,m,y])}}n.AlienSolanaSsoClient=ie,n.AlienSolanaSsoClientSchema=q,n.AlienSsoClient=x,n.AlienSsoClientSchema=j,n.AuthorizeRequestSchema=S,n.AuthorizeResponseSchema=z,n.ExchangeCodeRequestSchema=k,n.ExchangeCodeResponseSchema=E,n.PollRequestSchema=A,n.PollResponseSchema=h,n.SolanaAttestationRequestSchema=V,n.SolanaAttestationResponseSchema=N,n.SolanaLinkRequestSchema=D,n.SolanaLinkResponseSchema=O,n.SolanaPollRequestSchema=U,n.SolanaPollResponseSchema=L,n.TokenInfoSchema=C,n.VerifyTokenRequestSchema=B,n.VerifyTokenResponseSchema=T,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(t,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("zod/v4-mini"),require("js-sha256")):typeof define=="function"&&define.amd?define(["exports","zod/v4-mini","js-sha256"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t.AlienSsoCore={},t.Zod,t.jsSha256))})(this,(function(t,e,i){"use strict";var f=(t,e,i)=>new Promise((S,g)=>{var m=c=>{try{u(i.next(c))}catch(d){g(d)}},_=c=>{try{u(i.throw(c))}catch(d){g(d)}},u=c=>c.done?S(c.value):Promise.resolve(c.value).then(m,_);u((i=i.apply(t,e)).next())});const S=e.z.object({code_challenge:e.z.string(),code_challenge_method:e.z.literal("S256")}),g=e.z.object({deep_link:e.z.string(),polling_code:e.z.string(),expired_at:e.z.number()}),m=e.z.object({polling_code:e.z.string()}),_=["pending","authorized","rejected","expired"],u=e.z.enum(_),c=e.z.object({status:u,authorization_code:e.z.optional(e.z.string())}),d=e.z.object({authorization_code:e.z.string(),code_verifier:e.z.string()}),y=e.z.object({access_token:e.z.string()}),R=e.z.object({access_token:e.z.string()}),k=e.z.object({is_valid:e.z.boolean(),access_token:e.z.optional(e.z.string())}),A=e.z.object({app_callback_session_address:e.z.string(),expired_at:e.z.number(),issued_at:e.z.number()});function T(h){return btoa(h).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function j(h){let o=h.replace(/-/g,"+").replace(/_/g,"/");for(;o.length%4;)o+="=";return atob(o)}const C="https://sso.alien.com",w=5e3,l="alien-sso_",z=(h,o)=>new URL(o,h).toString(),b=e.z.object({ssoBaseUrl:e.z.url(),providerAddress:e.z.string(),pollingInterval:e.z.optional(e.z.number())});class E{constructor(o){this.config=b.parse(o),this.ssoBaseUrl=this.config.ssoBaseUrl||C,this.providerAddress=this.config.providerAddress,this.pollingInterval=this.config.pollingInterval||w}generateCodeVerifier(o=128){let s;const r=typeof window!="undefined"&&window.crypto;if(r&&r.getRandomValues)s=new Uint8Array(o),r.getRandomValues(s);else{s=new Uint8Array(o);for(let n=0;n<o;n++)s[n]=Math.floor(Math.random()*256)}let a="";for(let n=0;n<s.length;n++)a+=String.fromCharCode(s[n]);return T(a)}generateCodeChallenge(o){return i.sha256(o)}generateDeeplink(){return f(this,null,function*(){const o=this.generateCodeVerifier(),s=this.generateCodeChallenge(o);sessionStorage.setItem(l+"code_verifier",o);const r=`${this.config.ssoBaseUrl}/sso/authorize`,a={code_challenge:s,code_challenge_method:"S256"};S.parse(a);const p=yield(yield fetch(r,{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(a)})).json();return g.parse(p)})}pollAuth(o){return f(this,null,function*(){const s={polling_code:o};m.parse(s);const r=yield fetch(z(this.config.ssoBaseUrl,"/sso/poll"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(s)});if(!r.ok)throw new Error(`Poll failed: ${r.statusText}`);const a=yield r.json();return c.parse(a)})}exchangeToken(o){return f(this,null,function*(){const s=sessionStorage.getItem(l+"code_verifier");if(!s)throw new Error("Missing code verifier.");const r={authorization_code:o,code_verifier:s};d.parse(r);const a=yield fetch(z(this.config.ssoBaseUrl,"/sso/access_token/exchange"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(r)});if(!a.ok)throw new Error(`ExchangeCode failed: ${a.statusText}`);const n=yield a.json(),p=y.parse(n);if(p.access_token)return localStorage.setItem(l+"access_token",p.access_token),p.access_token;throw new Error("Exchange failed")})}verifyAuth(){return f(this,null,function*(){const o=this.getAccessToken();if(!o)return!1;const s={access_token:o};R.parse(s);const r=yield fetch(z(this.config.ssoBaseUrl,"/sso/access_token/verify"),{method:"POST",headers:{"Content-Type":"application/json","X-PROVIDER-ADDRESS":this.providerAddress},body:JSON.stringify(s)});if(!r.ok)return!1;const a=yield r.json(),n=k.parse(a);return n.access_token&&localStorage.setItem(l+"access_token",n.access_token),n.is_valid})}getAccessToken(){return localStorage.getItem(l+"access_token")}getAuthData(){const o=this.getAccessToken();if(!o)return null;const s=o.split(".");if(s.length!==3)return null;let r;try{const n=j(s[0]);r=JSON.parse(n)}catch(n){return null}if(r.alg!=="HS256"||r.typ!=="JWT")return null;let a;try{const n=JSON.parse(j(s[1]));a=A.parse(n)}catch(n){return null}return a}logout(){localStorage.removeItem(l+"access_token"),sessionStorage.removeItem(l+"code_verifier")}}t.AlienSsoClient=E,t.AlienSsoClientSchema=b,t.AuthorizeRequestSchema=S,t.AuthorizeResponseSchema=g,t.ExchangeCodeRequestSchema=d,t.ExchangeCodeResponseSchema=y,t.PollRequestSchema=m,t.PollResponseSchema=c,t.TokenInfoSchema=A,t.VerifyTokenRequestSchema=R,t.VerifyTokenResponseSchema=k,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alien_org/sso-sdk-core",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/alien-id/sso-sdk-js.git"
@@ -52,8 +52,5 @@
52
52
  "dependencies": {
53
53
  "js-sha256": "^0.11.1",
54
54
  "zod": "^4.1.5"
55
- },
56
- "peerDependencies": {
57
- "@solana/web3.js": "^1.95.0"
58
55
  }
59
56
  }