@lombard.finance/sdk-common 4.0.0 → 4.1.0-canary.11

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 u=Object.create;var s=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var S=(t,i,e,c)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of d(i))!b.call(t,n)&&n!==e&&s(t,n,{get:()=>i[n],enumerable:!(c=p(i,n))||c.enumerable});return t};var a=(t,i,e)=>(e=t!=null?u(l(t)):{},S(i||!t||!t.__esModule?s(e,"default",{value:t,enumerable:!0}):e,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o={prod:"prod",testnet:"testnet",stage:"stage",dev:"dev",ibc:"ibc"},g=o.prod,y=["evm","bitcoin","solana","sui","starknet"];let r=null;const E=async()=>{try{const t=await import("bitcoinjs-lib"),i=await import("@bitcoinerlab/secp256k1");try{t.initEccLib(i)}catch(e){if(!/already initialized/i.test(String(e)))throw e}return t}catch(t){throw r=null,new Error(`Failed to initialize bitcoinjs-lib: ${t instanceof Error?t.message:String(t)}. Ensure bitcoinjs-lib and @bitcoinerlab/secp256k1 peer dependencies are installed.`)}},v=async()=>(r||(r=E()),r);async function w(t,i=o.prod){const e=await v();return`0x${e.address.toOutputScript(t,i===o.prod?e.networks.bitcoin:e.networks.testnet).toString("hex")}`}exports.DEFAULT_ENV=g;exports.Env=o;exports.ProviderKeys=y;exports.getOutputScript=w;
1
+ "use strict";var p=Object.create;var s=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty;var E=(t,i,e,c)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of d(i))!l.call(t,n)&&n!==e&&s(t,n,{get:()=>i[n],enumerable:!(c=u(i,n))||c.enumerable});return t};var a=(t,i,e)=>(e=t!=null?p(S(t)):{},E(i||!t||!t.__esModule?s(e,"default",{value:t,enumerable:!0}):e,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o={prod:"prod",testnet:"testnet",stage:"stage",dev:"dev",ibc:"ibc"},T=o.prod,I=["evm","bitcoin","solana","sui","starknet"];let r=null;const b=async()=>{try{const t=await import("bitcoinjs-lib"),i=await import("@bitcoinerlab/secp256k1");try{t.initEccLib(i)}catch(e){if(!/already initialized/i.test(String(e)))throw e}return t}catch(t){throw r=null,new Error(`Failed to initialize bitcoinjs-lib: ${t instanceof Error?t.message:String(t)}. Ensure bitcoinjs-lib and @bitcoinerlab/secp256k1 peer dependencies are installed.`)}},A=async()=>(r||(r=b()),r);async function g(t,i=o.prod){const e=await A();return`0x${e.address.toOutputScript(t,i===o.prod?e.networks.bitcoin:e.networks.testnet).toString("hex")}`}const _={syncComplete:"VERIFICATION_STATUS_SYNC_COMPLETE",pending:"VERIFICATION_STATUS_PENDING",completeValid:"VERIFICATION_STATUS_COMPLETE_VALID"};exports.DEFAULT_ENV=T;exports.Env=o;exports.ProviderKeys=I;exports.VERIFICATION_STATUS=_;exports.getOutputScript=g;
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- const r = {
1
+ const o = {
2
2
  prod: "prod",
3
3
  testnet: "testnet",
4
4
  stage: "stage",
5
5
  dev: "dev",
6
6
  ibc: "ibc"
7
- }, p = r.prod, u = [
7
+ }, p = o.prod, u = [
8
8
  "evm",
9
9
  "bitcoin",
10
10
  "solana",
@@ -12,7 +12,7 @@ const r = {
12
12
  "starknet"
13
13
  ];
14
14
  let n = null;
15
- const o = async () => {
15
+ const r = async () => {
16
16
  try {
17
17
  const t = await import("bitcoinjs-lib"), e = await import("@bitcoinerlab/secp256k1");
18
18
  try {
@@ -27,17 +27,26 @@ const o = async () => {
27
27
  `Failed to initialize bitcoinjs-lib: ${t instanceof Error ? t.message : String(t)}. Ensure bitcoinjs-lib and @bitcoinerlab/secp256k1 peer dependencies are installed.`
28
28
  );
29
29
  }
30
- }, c = async () => (n || (n = o()), n);
31
- async function d(t, e = r.prod) {
30
+ }, c = async () => (n || (n = r()), n);
31
+ async function d(t, e = o.prod) {
32
32
  const i = await c();
33
33
  return `0x${i.address.toOutputScript(
34
34
  t,
35
- e === r.prod ? i.networks.bitcoin : i.networks.testnet
35
+ e === o.prod ? i.networks.bitcoin : i.networks.testnet
36
36
  ).toString("hex")}`;
37
37
  }
38
+ const l = {
39
+ /** Synchronous verification finished — JWT is in this same response. */
40
+ syncComplete: "VERIFICATION_STATUS_SYNC_COMPLETE",
41
+ /** Async verification started — poll with the returned `verification_id`. */
42
+ pending: "VERIFICATION_STATUS_PENDING",
43
+ /** Async verification succeeded — JWT is in the poll response. */
44
+ completeValid: "VERIFICATION_STATUS_COMPLETE_VALID"
45
+ };
38
46
  export {
39
47
  p as DEFAULT_ENV,
40
- r as Env,
48
+ o as Env,
41
49
  u as ProviderKeys,
50
+ l as VERIFICATION_STATUS,
42
51
  d as getOutputScript
43
52
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lombard.finance/sdk-common",
3
- "version": "4.0.0",
3
+ "version": "4.1.0-canary.11",
4
4
  "description": "Shared utilities and types for the Lombard SDK packages",
5
5
  "exports": {
6
6
  ".": {
package/src/modules.ts CHANGED
@@ -72,8 +72,10 @@ export interface SdkModule<TId extends string = string, TService = unknown> {
72
72
  * }
73
73
  * ```
74
74
  */
75
- export interface ChainModule<TChain extends string = string, TService = unknown>
76
- extends SdkModule<TChain, TService> {
75
+ export interface ChainModule<
76
+ TChain extends string = string,
77
+ TService = unknown,
78
+ > extends SdkModule<TChain, TService> {
77
79
  /** Chain type this module provides services for */
78
80
  chain: TChain;
79
81
  }
@@ -94,8 +96,10 @@ export type ModuleId<TModule> =
94
96
  /**
95
97
  * Extract service type from a module by ID
96
98
  */
97
- export type ServiceOf<TModule extends SdkModule<string, unknown>, TId extends string> =
98
- TModule extends SdkModule<TId, infer TService> ? TService : never;
99
+ export type ServiceOf<
100
+ TModule extends SdkModule<string, unknown>,
101
+ TId extends string,
102
+ > = TModule extends SdkModule<TId, infer TService> ? TService : never;
99
103
 
100
104
  /**
101
105
  * @deprecated Use ServiceOf instead
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Wallet Auth Service
3
+ *
4
+ * Contract for the wallet-based authentication flow used by the Lombard
5
+ * backend (v2):
6
+ *
7
+ * 1. `requestChallenge` — server returns a payload the wallet must sign.
8
+ * 2. `verifySignature` — server validates the signature and issues a JWT.
9
+ * 3. `revokeToken` — invalidates a JWT server-side (e.g. on disconnect).
10
+ *
11
+ * Signing the challenge with the user's wallet is intentionally NOT part of
12
+ * this contract — signing primitives are chain-specific and live in the
13
+ * corresponding chain SDK packages.
14
+ */
15
+
16
+ /**
17
+ * Supported chain identifiers accepted by the auth API.
18
+ *
19
+ * Free-form string to stay open to chains added on the backend before the
20
+ * SDK is updated. Common values: `'ethereum'`, `'solana'`, `'sui'`,
21
+ * `'starknet'`, `'cosmos'`.
22
+ */
23
+ export type WalletAuthChain = string;
24
+
25
+ export interface WalletChallengeRequest {
26
+ /** Wallet address performing the auth flow. */
27
+ address: string;
28
+ /** Chain the address belongs to. */
29
+ chain: WalletAuthChain;
30
+ }
31
+
32
+ export interface WalletChallengeResponse {
33
+ /** Random nonce embedded in the payload. */
34
+ nonce: string;
35
+ /** Chain-specific payload the user must sign with their wallet. */
36
+ payload: string;
37
+ /** ISO-8601 timestamp when this challenge expires. */
38
+ expiresAt: string;
39
+ }
40
+
41
+ export interface WalletVerifyRequest {
42
+ address: string;
43
+ /** The payload returned by `requestChallenge`. */
44
+ payload: string;
45
+ /** Signature produced by the wallet over `payload`. */
46
+ signature: string;
47
+ chain: WalletAuthChain;
48
+ /**
49
+ * Required for chains where the public key cannot be recovered from the
50
+ * signature (Starknet, Cosmos). Ignored elsewhere.
51
+ */
52
+ publicKey?: string;
53
+ }
54
+
55
+ /**
56
+ * Verification status returned by `/v2/auth/wallet/verify` and its polling
57
+ * endpoint. EVM EOAs / Sui / Solana verify synchronously and get a JWT
58
+ * immediately; EVM smart-contract wallets and Starknet verify asynchronously
59
+ * (the signature is checked on-chain), so the caller must poll for the JWT.
60
+ */
61
+ export const VERIFICATION_STATUS = {
62
+ /** Synchronous verification finished — JWT is in this same response. */
63
+ syncComplete: 'VERIFICATION_STATUS_SYNC_COMPLETE',
64
+ /** Async verification started — poll with the returned `verification_id`. */
65
+ pending: 'VERIFICATION_STATUS_PENDING',
66
+ /** Async verification succeeded — JWT is in the poll response. */
67
+ completeValid: 'VERIFICATION_STATUS_COMPLETE_VALID',
68
+ } as const;
69
+
70
+ /** Token pair issued once verification succeeds (sync or async). */
71
+ export interface WalletVerifyResult {
72
+ /** JWT bound to the verified wallet address. */
73
+ jwt: string;
74
+ /** ISO-8601 timestamp when the JWT expires. */
75
+ expiresAt: string;
76
+ }
77
+
78
+ /**
79
+ * Outcome of `POST /v2/auth/wallet/verify`: either an immediate token
80
+ * (`complete`, sync path) or a `verificationId` to poll while the signature is
81
+ * verified on-chain (`pending`, async path).
82
+ */
83
+ export type WalletVerifyResponse =
84
+ | ({ kind: 'complete' } & WalletVerifyResult)
85
+ | { kind: 'pending'; verificationId: string };
86
+
87
+ export interface RevokeWalletTokenRequest {
88
+ /** JWT to invalidate server-side. */
89
+ jwt: string;
90
+ }
91
+
92
+ export interface PollWalletVerificationRequest {
93
+ /** Id returned by `verifySignature` when the result is `pending`. */
94
+ verificationId: string;
95
+ }
96
+
97
+ /**
98
+ * Wallet auth service contract. Implementations live in `@lombard.finance/sdk`.
99
+ */
100
+ export interface WalletAuthService {
101
+ /** Request a challenge payload for the given wallet. */
102
+ requestChallenge(
103
+ params: WalletChallengeRequest,
104
+ ): Promise<WalletChallengeResponse>;
105
+
106
+ /**
107
+ * Submit a signed challenge. Resolves with a JWT (`complete`) on the sync
108
+ * path, or a `verificationId` (`pending`) that must be polled via
109
+ * `pollVerification` on the async path.
110
+ */
111
+ verifySignature(params: WalletVerifyRequest): Promise<WalletVerifyResponse>;
112
+
113
+ /**
114
+ * Poll the async verification endpoint until the on-chain signature check
115
+ * settles, resolving with the JWT. Only needed when `verifySignature`
116
+ * returns a `pending` result.
117
+ */
118
+ pollVerification(
119
+ params: PollWalletVerificationRequest,
120
+ ): Promise<WalletVerifyResult>;
121
+
122
+ /**
123
+ * Invalidate a JWT server-side. Best-effort: implementations may swallow
124
+ * network errors so callers can always clear local state.
125
+ */
126
+ revokeToken(params: RevokeWalletTokenRequest): Promise<void>;
127
+ }
@@ -13,6 +13,7 @@
13
13
 
14
14
  // Core services (provided by sdk)
15
15
  export * from './api';
16
+ export * from './auth';
16
17
  export * from './btc';
17
18
  export * from './evm';
18
19