@lombard.finance/sdk-common 3.4.0 → 3.5.0
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/LICENSE +21 -0
- package/README.md +21 -0
- package/dist/index.cjs +0 -1
- package/dist/index.js +0 -1
- package/package.json +22 -2
- package/src/services/api.ts +2 -0
- package/src/services/solana.ts +20 -0
- package/src/utils/btc-address-type.ts +0 -0
- package/src/utils/numbers.ts +0 -0
- package/src/vite-env.d.ts +0 -0
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Lombard Finance
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
1
|
# @lombard.finance/sdk-common
|
|
2
|
+
|
|
3
|
+
Shared utilities and types used internally by the [Lombard SDK](https://github.com/lombard-finance/sdk) packages.
|
|
4
|
+
|
|
5
|
+
## What's included
|
|
6
|
+
|
|
7
|
+
- Environment configuration (`Env`, chain definitions)
|
|
8
|
+
- Provider interfaces and abstractions
|
|
9
|
+
- Bitcoin output script generation utilities
|
|
10
|
+
- Chain service abstractions
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
This package is an internal dependency of `@lombard.finance/sdk`, `@lombard.finance/sdk-solana`, `@lombard.finance/sdk-starknet`, and `@lombard.finance/sdk-sui`. You typically do not need to install it directly.
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @lombard.finance/sdk-common
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## License
|
|
21
|
+
|
|
22
|
+
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +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;
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lombard.finance/sdk-common",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
|
+
"description": "Shared utilities and types for the Lombard SDK packages",
|
|
4
5
|
"exports": {
|
|
5
6
|
".": {
|
|
6
7
|
"types": "./src/index.ts",
|
|
@@ -14,7 +15,8 @@
|
|
|
14
15
|
"types": "./src/index.ts",
|
|
15
16
|
"files": [
|
|
16
17
|
"dist",
|
|
17
|
-
"src"
|
|
18
|
+
"src",
|
|
19
|
+
"LICENSE"
|
|
18
20
|
],
|
|
19
21
|
"engines": {
|
|
20
22
|
"node": ">= 18.0.0"
|
|
@@ -27,6 +29,24 @@
|
|
|
27
29
|
"format:check": "prettier --check \"src/**/*.{js,jsx,ts,tsx}\"",
|
|
28
30
|
"types": "tsc --noEmit"
|
|
29
31
|
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/lombard-finance/sdk.git",
|
|
35
|
+
"directory": "packages/sdk-common"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://docs.lombard.finance",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/lombard-finance/sdk/issues"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"lombard",
|
|
43
|
+
"sdk",
|
|
44
|
+
"common",
|
|
45
|
+
"utilities"
|
|
46
|
+
],
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
30
50
|
"peerDependencies": {
|
|
31
51
|
"@bitcoinerlab/secp256k1": "^1.2.0",
|
|
32
52
|
"bitcoinjs-lib": "^6.1.5"
|
package/src/services/api.ts
CHANGED
package/src/services/solana.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Env } from '../env';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Solana Chain Service
|
|
3
5
|
*
|
|
@@ -28,4 +30,22 @@ export interface SolanaService {
|
|
|
28
30
|
btcAddress: string;
|
|
29
31
|
network: string;
|
|
30
32
|
}): Promise<{ txHash: string }>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Redeem BTC.b on Solana to receive BTC
|
|
36
|
+
*
|
|
37
|
+
* Burns BTC.b on Solana and sends a GMP message to trigger
|
|
38
|
+
* a BTC payout to the specified Bitcoin address.
|
|
39
|
+
*
|
|
40
|
+
* @param args.amount - Amount of BTC.b to redeem in base units (satoshis)
|
|
41
|
+
* @param args.btcAddress - Bitcoin address to receive BTC
|
|
42
|
+
* @param args.network - Solana network ('mainnet-beta', 'devnet', 'testnet')
|
|
43
|
+
* @returns Transaction signature
|
|
44
|
+
*/
|
|
45
|
+
redeemForBtc(args: {
|
|
46
|
+
amount: string;
|
|
47
|
+
btcAddress: string;
|
|
48
|
+
network: string;
|
|
49
|
+
env?: Env;
|
|
50
|
+
}): Promise<{ txHash: string }>;
|
|
31
51
|
}
|
|
File without changes
|
package/src/utils/numbers.ts
CHANGED
|
File without changes
|
package/src/vite-env.d.ts
CHANGED
|
File without changes
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/env.ts","../src/providers.ts","../src/utils/bitcoin.ts","../src/utils/get-output-script.ts"],"sourcesContent":["export const Env = {\n prod: 'prod',\n testnet: 'testnet',\n stage: 'stage',\n dev: 'dev',\n ibc: 'ibc',\n} as const;\n\nexport type Env = (typeof Env)[keyof typeof Env];\n\nexport const DEFAULT_ENV: Env = Env.prod;\n","import type { EIP1193Provider } from 'viem';\n\n/**\n * Provider interfaces shared between the core SDK and optional chain modules.\n */\nexport interface EvmProvider extends EIP1193Provider {}\n\nexport interface BtcProvider {\n getAddresses(): Promise<string[]>;\n signMessage(message: string): Promise<string>;\n getNetwork?(): Promise<string>;\n}\n\nexport interface SolanaProvider {\n signMessage(message: Uint8Array | string): Promise<{ signature: Uint8Array }>;\n publicKey?: { toString(): string };\n network?: string;\n}\n\nexport interface SuiProvider {\n getWallet(): unknown;\n getWalletAccount(): unknown;\n}\n\nexport interface StarknetProvider {\n getProvider(): unknown;\n}\n\nexport type AnyProvider =\n | EvmProvider\n | BtcProvider\n | SolanaProvider\n | SuiProvider\n | StarknetProvider;\n\nexport const ProviderKeys = [\n 'evm',\n 'bitcoin',\n 'solana',\n 'sui',\n 'starknet',\n] as const;\nexport type ProviderKey = (typeof ProviderKeys)[number];\n\nexport interface ProviderMap {\n evm: EvmProvider;\n bitcoin: BtcProvider;\n solana: SolanaProvider;\n sui: SuiProvider;\n starknet: StarknetProvider;\n}\n\nexport type ProviderFor<TKey extends ProviderKey> = ProviderMap[TKey];\n","let bitcoinPromise: Promise<typeof import('bitcoinjs-lib')> | null = null;\n\nconst initBitcoin = async (): Promise<typeof import('bitcoinjs-lib')> => {\n try {\n const module = await import('bitcoinjs-lib');\n const ecc = await import('@bitcoinerlab/secp256k1');\n try {\n module.initEccLib(ecc);\n } catch (err) {\n if (!/already initialized/i.test(String(err))) {\n throw err;\n }\n }\n return module;\n } catch (err) {\n // Reset promise so subsequent calls can retry\n bitcoinPromise = null;\n throw new Error(\n `Failed to initialize bitcoinjs-lib: ${err instanceof Error ? err.message : String(err)}. ` +\n 'Ensure bitcoinjs-lib and @bitcoinerlab/secp256k1 peer dependencies are installed.',\n );\n }\n};\n\nexport const getBitcoin = async (): Promise<typeof import('bitcoinjs-lib')> => {\n if (!bitcoinPromise) {\n bitcoinPromise = initBitcoin();\n }\n return bitcoinPromise;\n};\n","import { Env } from '../env';\nimport { getBitcoin } from './bitcoin';\n\n/**\n * Get output script from address.\n *\n * @param address - The address.\n * @param env\n *\n * @returns The output script.\n */\nexport async function getOutputScript(\n address: string,\n env: Env = Env.prod,\n): Promise<`0x${string}`> {\n const bitcoin = await getBitcoin();\n const outputScriptBuf = bitcoin.address.toOutputScript(\n address,\n env === Env.prod ? bitcoin.networks.bitcoin : bitcoin.networks.testnet,\n );\n const outputScript = outputScriptBuf.toString('hex');\n return `0x${outputScript}`;\n}\n"],"names":["Env","DEFAULT_ENV","ProviderKeys","bitcoinPromise","initBitcoin","module","ecc","err","getBitcoin","getOutputScript","address","env","bitcoin"],"mappings":"2hBAAO,MAAMA,EAAM,CACjB,KAAM,OACN,QAAS,UACT,MAAO,QACP,IAAK,MACL,IAAK,KACP,EAIaC,EAAmBD,EAAI,KCyBvBE,EAAe,CAC1B,MACA,UACA,SACA,MACA,UACF,ECzCA,IAAIC,EAAiE,KAErE,MAAMC,EAAc,SAAqD,CACvE,GAAI,CACF,MAAMC,EAAS,KAAM,QAAO,eAAe,EACrCC,EAAM,KAAM,QAAO,yBAAyB,EAClD,GAAI,CACFD,EAAO,WAAWC,CAAG,CACvB,OAASC,EAAK,CACZ,GAAI,CAAC,uBAAuB,KAAK,OAAOA,CAAG,CAAC,EAC1C,MAAMA,CAEV,CACA,OAAOF,CACT,OAASE,EAAK,CAEZ,MAAAJ,EAAiB,KACX,IAAI,MACR,uCAAuCI,aAAe,MAAQA,EAAI,QAAU,OAAOA,CAAG,CAAC,qFAAA,CAG3F,CACF,EAEaC,EAAa,UACnBL,IACHA,EAAiBC,EAAA,GAEZD,GCjBT,eAAsBM,EACpBC,EACAC,EAAWX,EAAI,KACS,CACxB,MAAMY,EAAU,MAAMJ,EAAA,EAMtB,MAAO,KALiBI,EAAQ,QAAQ,eACtCF,EACAC,IAAQX,EAAI,KAAOY,EAAQ,SAAS,QAAUA,EAAQ,SAAS,OAAA,EAE5B,SAAS,KAAK,CAC3B,EAC1B"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/env.ts","../src/providers.ts","../src/utils/bitcoin.ts","../src/utils/get-output-script.ts"],"sourcesContent":["export const Env = {\n prod: 'prod',\n testnet: 'testnet',\n stage: 'stage',\n dev: 'dev',\n ibc: 'ibc',\n} as const;\n\nexport type Env = (typeof Env)[keyof typeof Env];\n\nexport const DEFAULT_ENV: Env = Env.prod;\n","import type { EIP1193Provider } from 'viem';\n\n/**\n * Provider interfaces shared between the core SDK and optional chain modules.\n */\nexport interface EvmProvider extends EIP1193Provider {}\n\nexport interface BtcProvider {\n getAddresses(): Promise<string[]>;\n signMessage(message: string): Promise<string>;\n getNetwork?(): Promise<string>;\n}\n\nexport interface SolanaProvider {\n signMessage(message: Uint8Array | string): Promise<{ signature: Uint8Array }>;\n publicKey?: { toString(): string };\n network?: string;\n}\n\nexport interface SuiProvider {\n getWallet(): unknown;\n getWalletAccount(): unknown;\n}\n\nexport interface StarknetProvider {\n getProvider(): unknown;\n}\n\nexport type AnyProvider =\n | EvmProvider\n | BtcProvider\n | SolanaProvider\n | SuiProvider\n | StarknetProvider;\n\nexport const ProviderKeys = [\n 'evm',\n 'bitcoin',\n 'solana',\n 'sui',\n 'starknet',\n] as const;\nexport type ProviderKey = (typeof ProviderKeys)[number];\n\nexport interface ProviderMap {\n evm: EvmProvider;\n bitcoin: BtcProvider;\n solana: SolanaProvider;\n sui: SuiProvider;\n starknet: StarknetProvider;\n}\n\nexport type ProviderFor<TKey extends ProviderKey> = ProviderMap[TKey];\n","let bitcoinPromise: Promise<typeof import('bitcoinjs-lib')> | null = null;\n\nconst initBitcoin = async (): Promise<typeof import('bitcoinjs-lib')> => {\n try {\n const module = await import('bitcoinjs-lib');\n const ecc = await import('@bitcoinerlab/secp256k1');\n try {\n module.initEccLib(ecc);\n } catch (err) {\n if (!/already initialized/i.test(String(err))) {\n throw err;\n }\n }\n return module;\n } catch (err) {\n // Reset promise so subsequent calls can retry\n bitcoinPromise = null;\n throw new Error(\n `Failed to initialize bitcoinjs-lib: ${err instanceof Error ? err.message : String(err)}. ` +\n 'Ensure bitcoinjs-lib and @bitcoinerlab/secp256k1 peer dependencies are installed.',\n );\n }\n};\n\nexport const getBitcoin = async (): Promise<typeof import('bitcoinjs-lib')> => {\n if (!bitcoinPromise) {\n bitcoinPromise = initBitcoin();\n }\n return bitcoinPromise;\n};\n","import { Env } from '../env';\nimport { getBitcoin } from './bitcoin';\n\n/**\n * Get output script from address.\n *\n * @param address - The address.\n * @param env\n *\n * @returns The output script.\n */\nexport async function getOutputScript(\n address: string,\n env: Env = Env.prod,\n): Promise<`0x${string}`> {\n const bitcoin = await getBitcoin();\n const outputScriptBuf = bitcoin.address.toOutputScript(\n address,\n env === Env.prod ? bitcoin.networks.bitcoin : bitcoin.networks.testnet,\n );\n const outputScript = outputScriptBuf.toString('hex');\n return `0x${outputScript}`;\n}\n"],"names":["Env","DEFAULT_ENV","ProviderKeys","bitcoinPromise","initBitcoin","module","ecc","err","getBitcoin","getOutputScript","address","env","bitcoin"],"mappings":"AAAO,MAAMA,IAAM;AAAA,EACjB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AAAA,EACP,KAAK;AAAA,EACL,KAAK;AACP,GAIaC,IAAmBD,EAAI,MCyBvBE,IAAe;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;ACzCA,IAAIC,IAAiE;AAErE,MAAMC,IAAc,YAAqD;AACvE,MAAI;AACF,UAAMC,IAAS,MAAM,OAAO,eAAe,GACrCC,IAAM,MAAM,OAAO,yBAAyB;AAClD,QAAI;AACF,MAAAD,EAAO,WAAWC,CAAG;AAAA,IACvB,SAASC,GAAK;AACZ,UAAI,CAAC,uBAAuB,KAAK,OAAOA,CAAG,CAAC;AAC1C,cAAMA;AAAA,IAEV;AACA,WAAOF;AAAA,EACT,SAASE,GAAK;AAEZ,UAAAJ,IAAiB,MACX,IAAI;AAAA,MACR,uCAAuCI,aAAe,QAAQA,EAAI,UAAU,OAAOA,CAAG,CAAC;AAAA,IAAA;AAAA,EAG3F;AACF,GAEaC,IAAa,aACnBL,MACHA,IAAiBC,EAAA,IAEZD;ACjBT,eAAsBM,EACpBC,GACAC,IAAWX,EAAI,MACS;AACxB,QAAMY,IAAU,MAAMJ,EAAA;AAMtB,SAAO,KALiBI,EAAQ,QAAQ;AAAA,IACtCF;AAAA,IACAC,MAAQX,EAAI,OAAOY,EAAQ,SAAS,UAAUA,EAAQ,SAAS;AAAA,EAAA,EAE5B,SAAS,KAAK,CAC3B;AAC1B;"}
|