@lombard.finance/sdk-common 1.0.0 → 3.0.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,2 @@
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;
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=g(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 g(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(l(t))return"p2wsh";throw new Error("Address type is not supported.")}function l(t){return(t.startsWith("bc1")||t.startsWith("tb1"))&&t.length===62}exports.DEFAULT_ENV=f;exports.Env=s;exports.getOutputScript=d;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/env.ts","../src/utils/get-output-script.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\nexport const DEFAULT_ENV: 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 '../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","DEFAULT_ENV","initEccLib","ecc","getOutputScript","address","env","addressType","getAddressType","paymentOutputScript","_a","payments","networks","result","addressUtils","isP2WSHAddressType"],"mappings":"ybAAaA,EAAM,CACjB,KAAM,OACN,QAAS,UACT,MAAO,OACT,EAIaC,EAAmBD,EAAI,KCCpCE,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 CHANGED
@@ -1,26 +1,26 @@
1
1
  import * as c from "@bitcoin-js/tiny-secp256k1-asmjs";
2
2
  import { initEccLib as u, payments as a, networks as i, address as d } from "bitcoinjs-lib";
3
- const r = {
3
+ const n = {
4
4
  prod: "prod",
5
5
  testnet: "testnet",
6
6
  stage: "stage"
7
- }, g = r.prod;
7
+ }, g = n.prod;
8
8
  u(c);
9
- function w(t, n = r.prod) {
9
+ function w(t, r = n.prod) {
10
10
  var s;
11
11
  const e = f(t), o = (s = a[e]({
12
12
  address: t,
13
- network: n === r.prod ? i.bitcoin : i.testnet
13
+ network: r === n.prod ? i.bitcoin : i.testnet
14
14
  }).output) == null ? void 0 : s.toString("hex");
15
15
  if (!o)
16
16
  throw new Error("Output script is not found.");
17
17
  return `0x${o}`;
18
18
  }
19
19
  function f(t) {
20
- const n = d.fromBech32(t);
21
- if (n.version === 1 && n.data.length === 32)
20
+ const r = d.fromBech32(t);
21
+ if (r.version === 1 && r.data.length === 32)
22
22
  return "p2tr";
23
- if (n.version === 0 && n.data.length === 20)
23
+ if (r.version === 0 && r.data.length === 20)
24
24
  return "p2wpkh";
25
25
  if (h(t))
26
26
  return "p2wsh";
@@ -30,8 +30,8 @@ function h(t) {
30
30
  return (t.startsWith("bc1") || t.startsWith("tb1")) && t.length === 62;
31
31
  }
32
32
  export {
33
- r as Env,
34
- g as defaultEnv,
33
+ g as DEFAULT_ENV,
34
+ n as Env,
35
35
  w as getOutputScript
36
36
  };
37
37
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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
+ {"version":3,"file":"index.js","sources":["../src/env.ts","../src/utils/get-output-script.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\nexport const DEFAULT_ENV: 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 '../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","DEFAULT_ENV","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,GAIaC,IAAmBD,EAAI;ACCpCE,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;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lombard.finance/sdk-common",
3
- "version": "1.0.0",
3
+ "version": "3.0.0",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.js",
@@ -16,12 +16,13 @@
16
16
  "src"
17
17
  ],
18
18
  "engines": {
19
- "node": ">= 18"
19
+ "node": ">= 22.14.0"
20
20
  },
21
21
  "scripts": {
22
- "types": "tsc --noEmit",
22
+ "build-docs": "rimraf ./sdk-docs && typedoc --out sdk-docs",
23
23
  "build": "yarn types && vite build",
24
- "build-docs": "rimraf ./sdk-docs && typedoc --out sdk-docs"
24
+ "lint": "biome lint",
25
+ "types": "tsc --noEmit"
25
26
  },
26
27
  "peerDependencies": {
27
28
  "@bitcoin-js/tiny-secp256k1-asmjs": "2.2.3",
@@ -34,4 +35,4 @@
34
35
  "typescript": "^5.4.5",
35
36
  "bitcoinjs-lib": "6.1.5"
36
37
  }
37
- }
38
+ }
@@ -5,3 +5,5 @@ export const Env = {
5
5
  } as const;
6
6
 
7
7
  export type Env = (typeof Env)[keyof typeof Env];
8
+
9
+ 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';
@@ -5,7 +5,7 @@ import {
5
5
  networks,
6
6
  payments,
7
7
  } from 'bitcoinjs-lib';
8
- import { Env } from '../../types/env';
8
+ import { Env } from '../env';
9
9
 
10
10
  initEccLib(ecc);
11
11
 
@@ -1,3 +0,0 @@
1
- import { Env } from '../types/env';
2
-
3
- export const defaultEnv: Env = Env.prod;