Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed May 30, 2024
0 parents commit c6ef297
Show file tree
Hide file tree
Showing 35 changed files with 7,214 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/actions/provision/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# @format

name: Provision
description: Set up Job with Tasks needed to run a Code Check
runs:
using: 'composite'
steps:
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: 20

- uses: actions/cache@v3
id: cache
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/package.json') }}
66 changes: 66 additions & 0 deletions .github/workflows/code-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# @format

name: Code Checks

on:
merge_group:
push:
branches:
- '**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: ./.github/actions/provision
with:
node-version: '20'

- name: Install dependencies
run: yarn install --ignore-optional

- name: Build
run: yarn build

lint-eslint:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/provision

- name: Lint
run: yarn lint:eslint

lint-prettier:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/provision

- name: Prettier
run: yarn lint:prettier

typecheck:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/provision

- name: Typecheck
run: yarn lint:typecheck

lint-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Commit Message
uses: wagoid/commitlint-github-action@v4
134 changes: 134 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Example JSON files
tb1ppxcqqtaxxqwclxudhervdnngzehpyr5mahczne64rkp2x7kvzfvqgda4ja.json
tb1q3ekr0u3s6clpag3tzaqk23f6edltxq3xl00hq8fjgugq5ds87jqsza5k55.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/
dist/
.prettierrc.js
.eslintrc.js
tsconfig.json
vite.config.ts
env.d.ts
19 changes: 19 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default {
printWidth: 100,
tabWidth: 2,
useTabs: false,
semi: true,
trailingComma: "es5",
singleQuote: true,
arrowParens: "avoid",
plugins: ["@trivago/prettier-plugin-sort-imports"],
importOrder: [
"^react",
"<THIRD_PARTY_MODULES>",
"^@shared/(.*)$",
"^@(app|content-script|inpage|background)/(.*)$",
"^[./]",
],
importOrderSeparation: true,
importOrderSortSpecifiers: true,
};
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Coming Soon
8 changes: 8 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(eslint.configs.recommended, ...tseslint.configs.recommended, {
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
});
75 changes: 75 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"type": "module",
"name": "dlc-btc-lib",
"version": "1.0.1",
"description": "This library provides a comprehensive set of interfaces and functions for minting dlcBTC tokens on supported blockchains.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"exports": {
".": "./dist/index.js",
"./utilities": "./dist/utilities/index.js",
"./constants": "./dist/constants/index.js",
"./models": "./dist/models/index.js",
"./bitcoin-functions": "./dist/functions/bitcoin/index.js",
"./ethereum-functions": "./dist/functions/ethereum/index.js"
},
"scripts": {
"clean": "rm -rf dist && rm -rf node_modules",
"build": "tsc",
"start": "node dist/example.js",
"test": "ts-node index.ts",
"lint": "concurrently -g 'yarn lint:eslint' 'yarn lint:prettier' 'yarn run lint:typecheck'",
"lint:eslint": "eslint \"src/**/*.{js,ts}\"",
"lint:eslint:fix": "eslint --fix \"src/**/*.{js,ts}\"",
"lint:prettier": "prettier --check \"{src,tests}/**/*.ts\" \"*.js\"",
"lint:prettier:fix": "prettier --write \"{src,tests}/**/*.ts\" *.js",
"lint:typecheck": "tsc --noEmit"
},
"keywords": [
"dlc",
"dlcbtc",
"dlclink",
"bitcoin",
"ethereum",
"token"
],
"author": "DLC.Link",
"license": "ISC",
"devDependencies": {
"@types/prompts": "^2.4.9",
"concurrently": "^8.2.2",
"eslint": "^9.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
"typescript": "4.7.4",
"typescript-eslint": "^7.7.0",
"@ledgerhq/hw-transport-node-hid": "^6.28.6",
"@ledgerhq/hw-transport-webusb": "^6.28.6",
"typecheck": "^0.1.2",
"prettier-eslint": "^16.3.0",
"lint": "^0.8.19",
"ls-lint": "^0.1.2",
"@trivago/prettier-plugin-sort-imports": "^4.3.0"
},
"dependencies": {
"@ledgerhq/hw-app-btc": "^10.2.4",
"@noble/hashes": "^1.4.0",
"@scure/base": "^1.1.6",
"@scure/btc-signer": "^1.3.1",
"bip32": "^4.0.0",
"bitcoinjs-lib": "^6.1.5",
"chalk": "^5.3.0",
"decimal.js": "^10.4.3",
"ethers": "5.7.2",
"ledger-bitcoin": "^0.2.3",
"noble": "^1.9.1",
"prompts": "^2.4.2",
"scure": "^1.6.0",
"tiny-secp256k1": "^2.2.3"
}
}
51 changes: 51 additions & 0 deletions src/attestor-handlers/attestor-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { AttestorError } from '../models/errors.js';

export class AttestorHandler {
private attestorRootURLs: string[];
private ethereumChainID: string;

constructor(
attestorRootURLs: string[],
ethereumChainID: 'evm-arbitrum' | 'evm-arbsepolia' | 'evm-localhost'
) {
this.attestorRootURLs = attestorRootURLs;
this.ethereumChainID = ethereumChainID;
}

async createPSBTEvent(
vaultUUID: string,
fundingTransaction: string,
closingPSBT: string,
userNativeSegwitAddress: string
): Promise<void> {
const createPSBTEndpoints = this.attestorRootURLs.map(url => `${url}/app/create-psbt-event`);

const body = JSON.stringify({
uuid: vaultUUID,
funding_transaction: fundingTransaction,
closing_psbt: closingPSBT,
mint_address: userNativeSegwitAddress,
chain: this.ethereumChainID,
});

const requests = createPSBTEndpoints.map(async url =>
fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' },
body,
})
.then(response => (response.ok ? true : response.statusText))
.catch(error => error.message)
);

const responses = await Promise.all(requests);

const failedResponses = responses.filter(response => response !== true);

if (failedResponses.length === createPSBTEndpoints.length) {
throw new AttestorError(
`Error sending Funding and Closing Transaction to Attestors: ${failedResponses.join(', ')}`
);
}
}
}
Loading

0 comments on commit c6ef297

Please sign in to comment.