@lombard.finance/sdk-common 1.0.0 → 3.1.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/dist/index.cjs CHANGED
@@ -1,2 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@bitcoin-js/tiny-secp256k1-asmjs"),r=require("bitcoinjs-lib");function p(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,o.get?o:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const a=p(u),s={prod:"prod",testnet:"testnet",stage:"stage"},f=s.prod;r.initEccLib(a);function d(t,e=s.prod){var c;const n=l(t),i=(c=r.payments[n]({address:t,network:e===s.prod?r.networks.bitcoin:r.networks.testnet}).output)==null?void 0:c.toString("hex");if(!i)throw new Error("Output script is not found.");return`0x${i}`}function l(t){const e=r.address.fromBech32(t);if(e.version===1&&e.data.length===32)return"p2tr";if(e.version===0&&e.data.length===20)return"p2wpkh";if(g(t))return"p2wsh";throw new Error("Address type is not supported.")}function g(t){return(t.startsWith("bc1")||t.startsWith("tb1"))&&t.length===62}exports.Env=s;exports.defaultEnv=f;exports.getOutputScript=d;
2
- //# sourceMappingURL=index.cjs.map
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@bitcoin-js/tiny-secp256k1-asmjs"),r=require("bitcoinjs-lib");function i(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const o in t)if(o!=="default"){const c=Object.getOwnPropertyDescriptor(t,o);Object.defineProperty(e,o,c.get?c:{enumerable:!0,get:()=>t[o]})}}return e.default=t,Object.freeze(e)}const p=i(u),n={prod:"prod",testnet:"testnet",stage:"stage",dev:"dev"},s=n.prod;r.initEccLib(p);function a(t,e=n.prod){return console.info(`Getting output script for ${t} (${e})`),`0x${r.address.toOutputScript(t,e===n.prod?r.networks.bitcoin:r.networks.testnet).toString("hex")}`}exports.DEFAULT_ENV=s;exports.Env=n;exports.getOutputScript=a;
package/dist/index.js CHANGED
@@ -1,37 +1,20 @@
1
1
  import * as c from "@bitcoin-js/tiny-secp256k1-asmjs";
2
- import { initEccLib as u, payments as a, networks as i, address as d } from "bitcoinjs-lib";
3
- const r = {
2
+ import { initEccLib as i, address as u, networks as r } from "bitcoinjs-lib";
3
+ const t = {
4
4
  prod: "prod",
5
5
  testnet: "testnet",
6
- stage: "stage"
7
- }, g = r.prod;
8
- u(c);
9
- function w(t, n = r.prod) {
10
- var s;
11
- const e = f(t), o = (s = a[e]({
12
- address: t,
13
- network: n === r.prod ? i.bitcoin : i.testnet
14
- }).output) == null ? void 0 : s.toString("hex");
15
- if (!o)
16
- throw new Error("Output script is not found.");
17
- return `0x${o}`;
18
- }
19
- function f(t) {
20
- const n = d.fromBech32(t);
21
- if (n.version === 1 && n.data.length === 32)
22
- return "p2tr";
23
- if (n.version === 0 && n.data.length === 20)
24
- return "p2wpkh";
25
- if (h(t))
26
- return "p2wsh";
27
- throw new Error("Address type is not supported.");
28
- }
29
- function h(t) {
30
- return (t.startsWith("bc1") || t.startsWith("tb1")) && t.length === 62;
6
+ stage: "stage",
7
+ dev: "dev"
8
+ }, d = t.prod;
9
+ i(c);
10
+ function f(o, p = t.prod) {
11
+ return console.info(`Getting output script for ${o} (${p})`), `0x${u.toOutputScript(
12
+ o,
13
+ p === t.prod ? r.bitcoin : r.testnet
14
+ ).toString("hex")}`;
31
15
  }
32
16
  export {
33
- r as Env,
34
- g as defaultEnv,
35
- w as getOutputScript
17
+ d as DEFAULT_ENV,
18
+ t as Env,
19
+ f as getOutputScript
36
20
  };
37
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,27 +1,25 @@
1
1
  {
2
2
  "name": "@lombard.finance/sdk-common",
3
- "version": "1.0.0",
3
+ "version": "3.1.0",
4
4
  "exports": {
5
5
  ".": {
6
+ "types": "./src/index.ts",
6
7
  "import": "./dist/index.js",
7
- "require": "./dist/index.cjs",
8
- "types": "./src/index.ts"
8
+ "require": "./dist/index.cjs"
9
9
  }
10
10
  },
11
11
  "license": "MIT",
12
12
  "type": "module",
13
13
  "types": "./src/index.ts",
14
- "files": [
15
- "dist",
16
- "src"
17
- ],
14
+ "files": ["dist", "src"],
18
15
  "engines": {
19
- "node": ">= 18"
16
+ "node": ">= 22.14.0"
20
17
  },
21
18
  "scripts": {
22
- "types": "tsc --noEmit",
19
+ "build-docs": "rimraf ./sdk-docs && typedoc --out sdk-docs",
23
20
  "build": "yarn types && vite build",
24
- "build-docs": "rimraf ./sdk-docs && typedoc --out sdk-docs"
21
+ "lint": "biome lint",
22
+ "types": "tsc --noEmit"
25
23
  },
26
24
  "peerDependencies": {
27
25
  "@bitcoin-js/tiny-secp256k1-asmjs": "2.2.3",
@@ -34,4 +32,4 @@
34
32
  "typescript": "^5.4.5",
35
33
  "bitcoinjs-lib": "6.1.5"
36
34
  }
37
- }
35
+ }
@@ -2,6 +2,9 @@ export const Env = {
2
2
  prod: 'prod',
3
3
  testnet: 'testnet',
4
4
  stage: 'stage',
5
+ dev: 'dev',
5
6
  } as const;
6
7
 
7
8
  export type Env = (typeof Env)[keyof typeof Env];
9
+
10
+ export const DEFAULT_ENV: Env = Env.prod;
package/src/index.ts CHANGED
@@ -1,3 +1,2 @@
1
- export * from './types/env';
2
- export * from './const/defaultEnv';
3
- export * from './btcSdk/utils/getOutputScript';
1
+ export * from './env';
2
+ export * from './utils/get-output-script';
@@ -0,0 +1,27 @@
1
+ import * as ecc from '@bitcoin-js/tiny-secp256k1-asmjs';
2
+ import { address as addressUtils, initEccLib, networks } from 'bitcoinjs-lib';
3
+ import { Env } from '../env';
4
+
5
+ initEccLib(ecc);
6
+
7
+ /**
8
+ * Get output script from address.
9
+ *
10
+ * @param address - The address.
11
+ * @param env
12
+ *
13
+ * @returns The output script.
14
+ */
15
+ export function getOutputScript(
16
+ address: string,
17
+ env: Env = Env.prod,
18
+ ): `0x${string}` {
19
+ console.info(`Getting output script for ${address} (${env})`);
20
+
21
+ const outputScriptBuf = addressUtils.toOutputScript(
22
+ address,
23
+ env === Env.prod ? networks.bitcoin : networks.testnet,
24
+ );
25
+ const outputScript = outputScriptBuf.toString('hex');
26
+ return `0x${outputScript}`;
27
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/types/env.ts","../src/const/defaultEnv.ts","../src/btcSdk/utils/getOutputScript.ts"],"sourcesContent":["export const Env = {\n prod: 'prod',\n testnet: 'testnet',\n stage: 'stage',\n} as const;\n\nexport type Env = (typeof Env)[keyof typeof Env];\n","import { Env } from '../types/env';\n\nexport const defaultEnv: Env = Env.prod;\n","import * as ecc from '@bitcoin-js/tiny-secp256k1-asmjs';\nimport {\n address as addressUtils,\n initEccLib,\n networks,\n payments,\n} from 'bitcoinjs-lib';\nimport { Env } from '../../types/env';\n\ninitEccLib(ecc);\n\ntype AddressType = 'p2tr' | 'p2wpkh' | 'p2wsh';\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 function getOutputScript(address: string, env: Env = Env.prod): string {\n const addressType = getAddressType(address);\n\n const payment = payments[addressType]({\n address,\n network: env === Env.prod ? networks.bitcoin : networks.testnet,\n });\n\n const paymentOutputScript = payment.output?.toString('hex');\n\n if (!paymentOutputScript) {\n throw new Error('Output script is not found.');\n }\n\n return `0x${paymentOutputScript}`;\n}\n\nfunction getAddressType(address: string): AddressType {\n const result = addressUtils.fromBech32(address);\n\n const isP2TR = result.version === 1 && result.data.length === 32;\n if (isP2TR) {\n return 'p2tr';\n }\n\n const isP2WPKH = result.version === 0 && result.data.length === 20;\n if (isP2WPKH) {\n return 'p2wpkh';\n }\n\n if (isP2WSHAddressType(address)) {\n return 'p2wsh';\n }\n\n throw new Error('Address type is not supported.');\n}\n\nfunction isP2WSHAddressType(address: string): boolean {\n return (\n (address.startsWith('bc1') || address.startsWith('tb1')) &&\n address.length === 62\n );\n}\n"],"names":["Env","defaultEnv","initEccLib","ecc","getOutputScript","address","env","addressType","getAddressType","paymentOutputScript","_a","payments","networks","result","addressUtils","isP2WSHAddressType"],"mappings":"ybAAaA,EAAM,CACjB,KAAM,OACN,QAAS,UACT,MAAO,OACT,ECFaC,EAAkBD,EAAI,KCOnCE,EAAA,WAAWC,CAAG,EAYP,SAASC,EAAgBC,EAAiBC,EAAWN,EAAI,KAAc,OACtE,MAAAO,EAAcC,EAAeH,CAAO,EAOpCI,GAAsBC,EALZC,WAASJ,CAAW,EAAE,CACpC,QAAAF,EACA,QAASC,IAAQN,EAAI,KAAOY,EAAA,SAAS,QAAUA,WAAS,OAAA,CACzD,EAEmC,SAAR,YAAAF,EAAgB,SAAS,OAErD,GAAI,CAACD,EACG,MAAA,IAAI,MAAM,6BAA6B,EAG/C,MAAO,KAAKA,CAAmB,EACjC,CAEA,SAASD,EAAeH,EAA8B,CAC9C,MAAAQ,EAASC,EAAAA,QAAa,WAAWT,CAAO,EAG9C,GADeQ,EAAO,UAAY,GAAKA,EAAO,KAAK,SAAW,GAErD,MAAA,OAIT,GADiBA,EAAO,UAAY,GAAKA,EAAO,KAAK,SAAW,GAEvD,MAAA,SAGL,GAAAE,EAAmBV,CAAO,EACrB,MAAA,QAGH,MAAA,IAAI,MAAM,gCAAgC,CAClD,CAEA,SAASU,EAAmBV,EAA0B,CAEjD,OAAAA,EAAQ,WAAW,KAAK,GAAKA,EAAQ,WAAW,KAAK,IACtDA,EAAQ,SAAW,EAEvB"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/types/env.ts","../src/const/defaultEnv.ts","../src/btcSdk/utils/getOutputScript.ts"],"sourcesContent":["export const Env = {\n prod: 'prod',\n testnet: 'testnet',\n stage: 'stage',\n} as const;\n\nexport type Env = (typeof Env)[keyof typeof Env];\n","import { Env } from '../types/env';\n\nexport const defaultEnv: Env = Env.prod;\n","import * as ecc from '@bitcoin-js/tiny-secp256k1-asmjs';\nimport {\n address as addressUtils,\n initEccLib,\n networks,\n payments,\n} from 'bitcoinjs-lib';\nimport { Env } from '../../types/env';\n\ninitEccLib(ecc);\n\ntype AddressType = 'p2tr' | 'p2wpkh' | 'p2wsh';\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 function getOutputScript(address: string, env: Env = Env.prod): string {\n const addressType = getAddressType(address);\n\n const payment = payments[addressType]({\n address,\n network: env === Env.prod ? networks.bitcoin : networks.testnet,\n });\n\n const paymentOutputScript = payment.output?.toString('hex');\n\n if (!paymentOutputScript) {\n throw new Error('Output script is not found.');\n }\n\n return `0x${paymentOutputScript}`;\n}\n\nfunction getAddressType(address: string): AddressType {\n const result = addressUtils.fromBech32(address);\n\n const isP2TR = result.version === 1 && result.data.length === 32;\n if (isP2TR) {\n return 'p2tr';\n }\n\n const isP2WPKH = result.version === 0 && result.data.length === 20;\n if (isP2WPKH) {\n return 'p2wpkh';\n }\n\n if (isP2WSHAddressType(address)) {\n return 'p2wsh';\n }\n\n throw new Error('Address type is not supported.');\n}\n\nfunction isP2WSHAddressType(address: string): boolean {\n return (\n (address.startsWith('bc1') || address.startsWith('tb1')) &&\n address.length === 62\n );\n}\n"],"names":["Env","defaultEnv","initEccLib","ecc","getOutputScript","address","env","addressType","getAddressType","paymentOutputScript","_a","payments","networks","result","addressUtils","isP2WSHAddressType"],"mappings":";;AAAO,MAAMA,IAAM;AAAA,EACjB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AACT,GCFaC,IAAkBD,EAAI;ACOnCE,EAAWC,CAAG;AAYP,SAASC,EAAgBC,GAAiBC,IAAWN,EAAI,MAAc;;AACtE,QAAAO,IAAcC,EAAeH,CAAO,GAOpCI,KAAsBC,IALZC,EAASJ,CAAW,EAAE;AAAA,IACpC,SAAAF;AAAA,IACA,SAASC,MAAQN,EAAI,OAAOY,EAAS,UAAUA,EAAS;AAAA,EAAA,CACzD,EAEmC,WAAR,gBAAAF,EAAgB,SAAS;AAErD,MAAI,CAACD;AACG,UAAA,IAAI,MAAM,6BAA6B;AAG/C,SAAO,KAAKA,CAAmB;AACjC;AAEA,SAASD,EAAeH,GAA8B;AAC9C,QAAAQ,IAASC,EAAa,WAAWT,CAAO;AAG9C,MADeQ,EAAO,YAAY,KAAKA,EAAO,KAAK,WAAW;AAErD,WAAA;AAIT,MADiBA,EAAO,YAAY,KAAKA,EAAO,KAAK,WAAW;AAEvD,WAAA;AAGL,MAAAE,EAAmBV,CAAO;AACrB,WAAA;AAGH,QAAA,IAAI,MAAM,gCAAgC;AAClD;AAEA,SAASU,EAAmBV,GAA0B;AAEjD,UAAAA,EAAQ,WAAW,KAAK,KAAKA,EAAQ,WAAW,KAAK,MACtDA,EAAQ,WAAW;AAEvB;"}
@@ -1,64 +0,0 @@
1
- import * as ecc from '@bitcoin-js/tiny-secp256k1-asmjs';
2
- import {
3
- address as addressUtils,
4
- initEccLib,
5
- networks,
6
- payments,
7
- } from 'bitcoinjs-lib';
8
- import { Env } from '../../types/env';
9
-
10
- initEccLib(ecc);
11
-
12
- type AddressType = 'p2tr' | 'p2wpkh' | 'p2wsh';
13
-
14
- /**
15
- * Get output script from address.
16
- *
17
- * @param address - The address.
18
- * @param env
19
- *
20
- * @returns The output script.
21
- */
22
- export function getOutputScript(address: string, env: Env = Env.prod): string {
23
- const addressType = getAddressType(address);
24
-
25
- const payment = payments[addressType]({
26
- address,
27
- network: env === Env.prod ? networks.bitcoin : networks.testnet,
28
- });
29
-
30
- const paymentOutputScript = payment.output?.toString('hex');
31
-
32
- if (!paymentOutputScript) {
33
- throw new Error('Output script is not found.');
34
- }
35
-
36
- return `0x${paymentOutputScript}`;
37
- }
38
-
39
- function getAddressType(address: string): AddressType {
40
- const result = addressUtils.fromBech32(address);
41
-
42
- const isP2TR = result.version === 1 && result.data.length === 32;
43
- if (isP2TR) {
44
- return 'p2tr';
45
- }
46
-
47
- const isP2WPKH = result.version === 0 && result.data.length === 20;
48
- if (isP2WPKH) {
49
- return 'p2wpkh';
50
- }
51
-
52
- if (isP2WSHAddressType(address)) {
53
- return 'p2wsh';
54
- }
55
-
56
- throw new Error('Address type is not supported.');
57
- }
58
-
59
- function isP2WSHAddressType(address: string): boolean {
60
- return (
61
- (address.startsWith('bc1') || address.startsWith('tb1')) &&
62
- address.length === 62
63
- );
64
- }
@@ -1,3 +0,0 @@
1
- import { Env } from '../types/env';
2
-
3
- export const defaultEnv: Env = Env.prod;