@tuwaio/quasar-sdk 1.0.0-fix-docs-alpha.4.494fbc9 → 1.0.0-fix-docs-alpha.6.248399a
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/README.md +19 -4
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,10 +15,13 @@ pnpm add @tuwaio/quasar-sdk ofetch
|
|
|
15
15
|
|
|
16
16
|
### Peer Dependencies
|
|
17
17
|
|
|
18
|
-
| Package | Version |
|
|
19
|
-
| --------------------- | --------- |
|
|
20
|
-
| `@tuwaio/pulsar-core` | `>=0.6.0` |
|
|
21
|
-
| `ofetch` | `>=1.5.1` |
|
|
18
|
+
| Package | Version | Requirement |
|
|
19
|
+
| --------------------- | --------- | ----------------------------------------- |
|
|
20
|
+
| `@tuwaio/pulsar-core` | `>=0.6.0` | **Required** (Core types) |
|
|
21
|
+
| `ofetch` | `>=1.5.1` | **Required** (Transport) |
|
|
22
|
+
| `viem` | `^2.0.0` | Optional (EVM Auth & Signing) |
|
|
23
|
+
| `gill` | `^0.14.0` | Optional (Solana Auth & Signing) |
|
|
24
|
+
| `zustand` | `^5.0.0` | Optional (Persistent Session Management) |
|
|
22
25
|
|
|
23
26
|
## Quick Start
|
|
24
27
|
|
|
@@ -43,6 +46,18 @@ const history = await quasar.pulsar.getHistory({ chainId: 1 });
|
|
|
43
46
|
| `syncCreate(tx, appName?)` | Sync a new pending transaction to the cloud |
|
|
44
47
|
| `getHistory(query?)` | Retrieve paginated transaction history with filters |
|
|
45
48
|
|
|
49
|
+
### Utils — `utils`
|
|
50
|
+
|
|
51
|
+
Security and authentication utilities. These can be used as standalone functions (ideal for frontends).
|
|
52
|
+
|
|
53
|
+
| Method | Description |
|
|
54
|
+
| ------------------------------ | ------------------------------------------------------ |
|
|
55
|
+
| `createMiniSessionMessage(ts)` | Format a standard login message for signing |
|
|
56
|
+
| `signMiniSession(params)` | Trigger signature request in the connected wallet |
|
|
57
|
+
| `verifyMiniSession(params)` | Verify an EVM or Solana signature with expiration check |
|
|
58
|
+
| `createMiniSessionStore(name)` | Create a persistent Zustand store for session caching |
|
|
59
|
+
| `getMiniSessionAuth(conn, st)` | Reusable helper for signing and caching logic |
|
|
60
|
+
|
|
46
61
|
## Error Handling
|
|
47
62
|
|
|
48
63
|
```typescript
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var ofetch=require('ofetch'),zustand=require('zustand'),middleware=require('zustand/middleware');var d="https://api.tuwa.io",p="/v1/engine/pulsar/sync",m="/v1/engine/pulsar/history";var c=class extends Error{status;originalError;constructor(e,r,s){super(e),this.name="QuasarSDKError",this.status=r,this.originalError=s;}},l=class{secretKey;internalSecret;baseUrl;timeout;constructor(e){if(!e.secretKey)throw new Error("[Quasar SDK] Missing API Key. Provide a secretKey starting with sk_live_.");this.secretKey=e.secretKey,this.internalSecret=e.internalSecret,this.baseUrl=e.baseUrl||d,this.timeout=e.timeout||1e4;}async request(e,r={}){try{return await ofetch.ofetch(e,{baseURL:this.baseUrl,timeout:this.timeout,...r,headers:{"Content-Type":"application/json","x-tuwa-secret-key":this.secretKey,...this.internalSecret?{"x-internal-secret":this.internalSecret}:{},...r.headers}})}catch(s){throw this.buildError(s)}}buildError(e){let r=e,s=r.statusCode??r.response?.status,n=(r.data??r.response?._data)?.error??r.message??"Unknown Error";return (s===401||s===403)&&console.error("\u{1F6A8} [Quasar SDK] Auth Error. Check your Secret Key and scopes."),new c(`[Quasar SDK] Request Failed (${s}): ${n}`,s,r)}};var a=class{constructor(e){this.client=e;}async syncCreate(e,r){return this.client.request(p,{method:"POST",body:{...e,appName:r}})}async getHistory(e={}){return this.client.request(m,{method:"GET",query:{page:e.page??1,limit:e.limit??10,chainId:e.chainId,status:e.status,txKey:e.txKey,appName:e.appName,walletAddress:e.walletAddress}})}};var S=(r=>(r.EVM="EVM",r.SOLANA="SOLANA",r))(S||{});var
|
|
2
|
-
exports.BASE_API_URL=d;exports.ChainType=S;exports.PULSAR_HISTORY_ENDPOINT=m;exports.PULSAR_SYNC_ENDPOINT=p;exports.PulsarModule=a;exports.Quasar=w;exports.QuasarSDKError=c;exports.createMiniSessionMessage=u;exports.createMiniSessionStore=y;exports.getMiniSessionAuth=f;exports.signMiniSession=g;exports.utils=
|
|
1
|
+
'use strict';var ofetch=require('ofetch'),zustand=require('zustand'),middleware=require('zustand/middleware');var d="https://api.tuwa.io",p="/v1/engine/pulsar/sync",m="/v1/engine/pulsar/history";var c=class extends Error{status;originalError;constructor(e,r,s){super(e),this.name="QuasarSDKError",this.status=r,this.originalError=s;}},l=class{secretKey;internalSecret;baseUrl;timeout;constructor(e){if(!e.secretKey)throw new Error("[Quasar SDK] Missing API Key. Provide a secretKey starting with sk_live_.");this.secretKey=e.secretKey,this.internalSecret=e.internalSecret,this.baseUrl=e.baseUrl||d,this.timeout=e.timeout||1e4;}async request(e,r={}){try{return await ofetch.ofetch(e,{baseURL:this.baseUrl,timeout:this.timeout,...r,headers:{"Content-Type":"application/json","x-tuwa-secret-key":this.secretKey,...this.internalSecret?{"x-internal-secret":this.internalSecret}:{},...r.headers}})}catch(s){throw this.buildError(s)}}buildError(e){let r=e,s=r.statusCode??r.response?.status,n=(r.data??r.response?._data)?.error??r.message??"Unknown Error";return (s===401||s===403)&&console.error("\u{1F6A8} [Quasar SDK] Auth Error. Check your Secret Key and scopes."),new c(`[Quasar SDK] Request Failed (${s}): ${n}`,s,r)}};var a=class{constructor(e){this.client=e;}async syncCreate(e,r){return this.client.request(p,{method:"POST",body:{...e,appName:r}})}async getHistory(e={}){return this.client.request(m,{method:"GET",query:{page:e.page??1,limit:e.limit??10,chainId:e.chainId,status:e.status,txKey:e.txKey,appName:e.appName,walletAddress:e.walletAddress}})}};var S=(r=>(r.EVM="EVM",r.SOLANA="SOLANA",r))(S||{});var x=300*1e3,E=60*1e3;function u(t){return `Mini-Session Login: ${t}`}async function g(t){let e=new Date().toISOString(),r=u(e);if(t.chainType==="EVM"){if(!t.walletAddress)throw new Error("[SDK] walletAddress is required for EVM signing.");try{return {signature:await t.signer.signMessage({account:t.walletAddress,message:r}),timestamp:e}}catch(s){throw new Error(`[SDK] EVM signing failed: ${s.message}`,{cause:s})}}if(t.chainType==="SOLANA"){let s;try{s=await import('gill');}catch(i){throw new Error('[SDK] Peer dependency "gill" is required for Solana signing.',{cause:i})}try{let n=s.getUtf8Encoder().encode(r),[o]=await t.signer.signMessages([n]),A=o instanceof Uint8Array?o:new Uint8Array(o);return {signature:s.getSignatureFromBytes(A),timestamp:e}}catch(i){throw new Error(`[SDK] Solana signing failed: ${i.message}`,{cause:i})}}throw new Error(`[SDK] Unsupported chain type: ${t.chainType}`)}async function h(t){let e=new Date(t.timestamp).getTime(),r=Date.now();if(isNaN(e))throw new Error("[SDK] Invalid timestamp format. Use ISO string.");let s=t.maxAge??x;if(r-e>s)throw new Error("[SDK] Signature expired. Please sign a fresh message.");if(e>r+E)throw new Error("[SDK] Timestamp is in the future. Check your system clock.");let i=u(t.timestamp);if(t.chainType==="EVM"){let n;try{n=await import('viem');}catch(o){throw new Error('[SDK] Peer dependency "viem" is required for EVM verification.',{cause:o})}return await n.verifyMessage({address:t.walletAddress,message:i,signature:t.signature})}if(t.chainType==="SOLANA"){let n;try{n=await import('gill');}catch(o){throw new Error('[SDK] Peer dependency "gill" is required for Solana verification.',{cause:o})}try{return await n.verifySignatureForAddress(n.address(t.walletAddress),t.signature,i)}catch{return false}}return false}function y(t="mini-session-storage"){return zustand.create()(middleware.persist(e=>({miniSession:null,setMiniSession:r=>e({miniSession:r}),clearSession:()=>e({miniSession:null})}),{name:t}))}async function f(t,e){if(!t.isConnected||!t.address)throw new Error("Wallet not connected. Please connect your wallet first.");let{address:r,chainType:s,signer:i}=t;if(e.miniSession&&e.miniSession.walletAddress===r&&e.miniSession.chainType===s)return e.miniSession;let o={...await g({signer:i,walletAddress:r,chainType:s}),chainType:s,walletAddress:r};return e.setMiniSession(o),o}var K={createMiniSessionMessage:u,verifyMiniSession:h,signMiniSession:g,createMiniSessionStore:y,getMiniSessionAuth:f},w=class{static utils=K;client;pulsar;constructor(e){this.client=new l(e),this.pulsar=new a(this.client);}};
|
|
2
|
+
exports.BASE_API_URL=d;exports.ChainType=S;exports.PULSAR_HISTORY_ENDPOINT=m;exports.PULSAR_SYNC_ENDPOINT=p;exports.PulsarModule=a;exports.Quasar=w;exports.QuasarSDKError=c;exports.createMiniSessionMessage=u;exports.createMiniSessionStore=y;exports.getMiniSessionAuth=f;exports.signMiniSession=g;exports.utils=K;exports.verifyMiniSession=h;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {ofetch}from'ofetch';import {create}from'zustand';import {persist}from'zustand/middleware';var d="https://api.tuwa.io",p="/v1/engine/pulsar/sync",m="/v1/engine/pulsar/history";var c=class extends Error{status;originalError;constructor(e,r,s){super(e),this.name="QuasarSDKError",this.status=r,this.originalError=s;}},l=class{secretKey;internalSecret;baseUrl;timeout;constructor(e){if(!e.secretKey)throw new Error("[Quasar SDK] Missing API Key. Provide a secretKey starting with sk_live_.");this.secretKey=e.secretKey,this.internalSecret=e.internalSecret,this.baseUrl=e.baseUrl||d,this.timeout=e.timeout||1e4;}async request(e,r={}){try{return await ofetch(e,{baseURL:this.baseUrl,timeout:this.timeout,...r,headers:{"Content-Type":"application/json","x-tuwa-secret-key":this.secretKey,...this.internalSecret?{"x-internal-secret":this.internalSecret}:{},...r.headers}})}catch(s){throw this.buildError(s)}}buildError(e){let r=e,s=r.statusCode??r.response?.status,n=(r.data??r.response?._data)?.error??r.message??"Unknown Error";return (s===401||s===403)&&console.error("\u{1F6A8} [Quasar SDK] Auth Error. Check your Secret Key and scopes."),new c(`[Quasar SDK] Request Failed (${s}): ${n}`,s,r)}};var a=class{constructor(e){this.client=e;}async syncCreate(e,r){return this.client.request(p,{method:"POST",body:{...e,appName:r}})}async getHistory(e={}){return this.client.request(m,{method:"GET",query:{page:e.page??1,limit:e.limit??10,chainId:e.chainId,status:e.status,txKey:e.txKey,appName:e.appName,walletAddress:e.walletAddress}})}};var S=(r=>(r.EVM="EVM",r.SOLANA="SOLANA",r))(S||{});var
|
|
2
|
-
export{d as BASE_API_URL,S as ChainType,m as PULSAR_HISTORY_ENDPOINT,p as PULSAR_SYNC_ENDPOINT,a as PulsarModule,w as Quasar,c as QuasarSDKError,u as createMiniSessionMessage,y as createMiniSessionStore,f as getMiniSessionAuth,g as signMiniSession,
|
|
1
|
+
import {ofetch}from'ofetch';import {create}from'zustand';import {persist}from'zustand/middleware';var d="https://api.tuwa.io",p="/v1/engine/pulsar/sync",m="/v1/engine/pulsar/history";var c=class extends Error{status;originalError;constructor(e,r,s){super(e),this.name="QuasarSDKError",this.status=r,this.originalError=s;}},l=class{secretKey;internalSecret;baseUrl;timeout;constructor(e){if(!e.secretKey)throw new Error("[Quasar SDK] Missing API Key. Provide a secretKey starting with sk_live_.");this.secretKey=e.secretKey,this.internalSecret=e.internalSecret,this.baseUrl=e.baseUrl||d,this.timeout=e.timeout||1e4;}async request(e,r={}){try{return await ofetch(e,{baseURL:this.baseUrl,timeout:this.timeout,...r,headers:{"Content-Type":"application/json","x-tuwa-secret-key":this.secretKey,...this.internalSecret?{"x-internal-secret":this.internalSecret}:{},...r.headers}})}catch(s){throw this.buildError(s)}}buildError(e){let r=e,s=r.statusCode??r.response?.status,n=(r.data??r.response?._data)?.error??r.message??"Unknown Error";return (s===401||s===403)&&console.error("\u{1F6A8} [Quasar SDK] Auth Error. Check your Secret Key and scopes."),new c(`[Quasar SDK] Request Failed (${s}): ${n}`,s,r)}};var a=class{constructor(e){this.client=e;}async syncCreate(e,r){return this.client.request(p,{method:"POST",body:{...e,appName:r}})}async getHistory(e={}){return this.client.request(m,{method:"GET",query:{page:e.page??1,limit:e.limit??10,chainId:e.chainId,status:e.status,txKey:e.txKey,appName:e.appName,walletAddress:e.walletAddress}})}};var S=(r=>(r.EVM="EVM",r.SOLANA="SOLANA",r))(S||{});var x=300*1e3,E=60*1e3;function u(t){return `Mini-Session Login: ${t}`}async function g(t){let e=new Date().toISOString(),r=u(e);if(t.chainType==="EVM"){if(!t.walletAddress)throw new Error("[SDK] walletAddress is required for EVM signing.");try{return {signature:await t.signer.signMessage({account:t.walletAddress,message:r}),timestamp:e}}catch(s){throw new Error(`[SDK] EVM signing failed: ${s.message}`,{cause:s})}}if(t.chainType==="SOLANA"){let s;try{s=await import('gill');}catch(i){throw new Error('[SDK] Peer dependency "gill" is required for Solana signing.',{cause:i})}try{let n=s.getUtf8Encoder().encode(r),[o]=await t.signer.signMessages([n]),A=o instanceof Uint8Array?o:new Uint8Array(o);return {signature:s.getSignatureFromBytes(A),timestamp:e}}catch(i){throw new Error(`[SDK] Solana signing failed: ${i.message}`,{cause:i})}}throw new Error(`[SDK] Unsupported chain type: ${t.chainType}`)}async function h(t){let e=new Date(t.timestamp).getTime(),r=Date.now();if(isNaN(e))throw new Error("[SDK] Invalid timestamp format. Use ISO string.");let s=t.maxAge??x;if(r-e>s)throw new Error("[SDK] Signature expired. Please sign a fresh message.");if(e>r+E)throw new Error("[SDK] Timestamp is in the future. Check your system clock.");let i=u(t.timestamp);if(t.chainType==="EVM"){let n;try{n=await import('viem');}catch(o){throw new Error('[SDK] Peer dependency "viem" is required for EVM verification.',{cause:o})}return await n.verifyMessage({address:t.walletAddress,message:i,signature:t.signature})}if(t.chainType==="SOLANA"){let n;try{n=await import('gill');}catch(o){throw new Error('[SDK] Peer dependency "gill" is required for Solana verification.',{cause:o})}try{return await n.verifySignatureForAddress(n.address(t.walletAddress),t.signature,i)}catch{return false}}return false}function y(t="mini-session-storage"){return create()(persist(e=>({miniSession:null,setMiniSession:r=>e({miniSession:r}),clearSession:()=>e({miniSession:null})}),{name:t}))}async function f(t,e){if(!t.isConnected||!t.address)throw new Error("Wallet not connected. Please connect your wallet first.");let{address:r,chainType:s,signer:i}=t;if(e.miniSession&&e.miniSession.walletAddress===r&&e.miniSession.chainType===s)return e.miniSession;let o={...await g({signer:i,walletAddress:r,chainType:s}),chainType:s,walletAddress:r};return e.setMiniSession(o),o}var K={createMiniSessionMessage:u,verifyMiniSession:h,signMiniSession:g,createMiniSessionStore:y,getMiniSessionAuth:f},w=class{static utils=K;client;pulsar;constructor(e){this.client=new l(e),this.pulsar=new a(this.client);}};
|
|
2
|
+
export{d as BASE_API_URL,S as ChainType,m as PULSAR_HISTORY_ENDPOINT,p as PULSAR_SYNC_ENDPOINT,a as PulsarModule,w as Quasar,c as QuasarSDKError,u as createMiniSessionMessage,y as createMiniSessionStore,f as getMiniSessionAuth,g as signMiniSession,K as utils,h as verifyMiniSession};
|