Skip to content

Commit

Permalink
Merge pull request #13 from Dartroom/12-improve-package-setup
Browse files Browse the repository at this point in the history
12 improve package setup
  • Loading branch information
stefdegroot committed Feb 3, 2023
2 parents beb90f7 + d97fc85 commit 5b38953
Show file tree
Hide file tree
Showing 12 changed files with 2,792 additions and 401 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI

on:
push:
branches:
- "**"

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest ]
node: [ 16 ]

steps:
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Checkout
uses: actions/checkout@v3

- name: Cache node_modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ matrix.os }}-node-v${{ matrix.node }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/package-lock.json')) }}

- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm install

- name: Lint
run: npm run lint

- name: Build
run: npm run build
2,961 changes: 2,616 additions & 345 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "@dartroom/dart-signer",
"version": "0.2.1-alpha",
"description": "A package that aggregates all Algorand signing options into one interface. Handles signing and address/login management.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"version": "0.3.0-alpha",
"description": "A package that aggregates multiple Algorand signing options into one interface. Handles signing and address/login management.",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist/"
],
"scripts": {
"build": "tsc -p tsconfig-esm.json && tsc -p tsconfig-cjs.json",
"test": "echo \"Error: no test specified\" && exit 1"
"build": "tsup index.ts --format cjs,esm --dts",
"lint": "tsc"
},
"repository": "git://github.com/Dartroom/dart-signer.git",
"keywords": [
Expand All @@ -26,10 +26,12 @@
"registry": "https://npm.pkg.github.com/dartroom"
},
"devDependencies": {
"@types/node": "^18.11.18",
"tsup": "^6.5.0",
"typescript": "^4.8.2"
},
"dependencies": {
"@perawallet/connect": "^1.0.3",
"@perawallet/connect": "^1.1.0",
"@randlabs/myalgo-connect": "^1.4.0",
"algosdk": "^1.23.2",
"buffer": "^6.0.3"
Expand Down
36 changes: 28 additions & 8 deletions src/algoSigner/signTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,31 @@ export default async function sign ({ algoSigner }: Provider, txns: Array<Array<
const unsignedTxns: Array<Txn> = []

for (let g = 0; g < txns.length; g++) {
for (let t = 0; t < txns[g].length; t++) {

const txnArray = txns[g]

if (!txnArray) {
throw new Error('Failed to parse transaction array.')
}

for (let t = 0; t < txnArray.length; t++) {

const txn = txnArray[t]

if (!txn) {
throw new Error('Failed to parse transaction array.')
}

unsignedTxns.push(txns[g][t])
unsignedTxns.push(txn)

if (txns[g][t].signers.length > 1) {
if (txn.signers.length > 1) {
binaryTxns.push({
txn: algoSigner.encoding.msgpackToBase64(txns[g][t].blob),
signers: txns[g][t].signers
txn: algoSigner.encoding.msgpackToBase64(txn.blob),
signers: txn.signers
})
} else {
binaryTxns.push({
txn: algoSigner.encoding.msgpackToBase64(txns[g][t].blob)
txn: algoSigner.encoding.msgpackToBase64(txn.blob)
})
}
}
Expand All @@ -32,10 +45,17 @@ export default async function sign ({ algoSigner }: Provider, txns: Array<Array<

if (signedTxns.length > 0) {
return signedTxns.map((txn, i) => {

const unsignedTxn = unsignedTxns[i]

if (!unsignedTxn) {
throw new Error('Failed to parse transaction array.')
}

return {
blob: Uint8Array.from(atob(txn.blob), c => c.charCodeAt(0)),
txID: unsignedTxns[i].txID,
signers: unsignedTxns[i].signers
txID: unsignedTxn.txID,
signers: unsignedTxn.signers
}
})
} else {
Expand Down
31 changes: 26 additions & 5 deletions src/exodus/signTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,40 @@ export default async function sign ({ exodus }: Provider, txns: Array<Array<Txn>
const unsignedTxns: Array<Txn> = []

for (let g = 0; g < txns.length; g++) {
for (let t = 0; t < txns[g].length; t++) {
binaryTxns.push(decodeUnsignedTransaction(txns[g][t].blob).toByte())
unsignedTxns.push(txns[g][t])

const txnArray = txns[g]

if (!txnArray) {
throw new Error('Failed to parse transaction array.')
}

for (let t = 0; t < txnArray.length; t++) {

const txn = txnArray[t]

if (!txn) {
throw new Error('Failed to parse transaction array.')
}

binaryTxns.push(decodeUnsignedTransaction(txn.blob).toByte())
unsignedTxns.push(txn)
}
}

const signedTxns = await exodus.signTransaction(binaryTxns) as Array<Uint8Array>

return signedTxns.map((blob, i) => {

const unsignedTxn = unsignedTxns[i]

if (!unsignedTxn) {
throw new Error('Failed to parse transaction array.')
}

return {
blob: blob,
signers: unsignedTxns[i].signers,
txID: unsignedTxns[i].txID
signers: unsignedTxn.signers,
txID: unsignedTxn.txID
}
})
}
3 changes: 1 addition & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ export class Wallet {
constructor (options?: { ledger?: Ledgers}) {
this.myAlgo = new MyAlgoConnect()
this.pera = new PeraWalletConnect({
shouldShowSignTxnToast: false,
network: options?.ledger === Ledgers.MAINNET ? 'mainnet' : 'testnet'
shouldShowSignTxnToast: false
})
this.algoSigner = this.setAlgoSigner()
this.exodus = this.setExodus()
Expand Down
31 changes: 26 additions & 5 deletions src/myAlgo/signTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,41 @@ export default async function sign ({ }: Provider, txns: Array<Array<Txn>>): Pro
const unsignedTxns: Array<Txn> = []

for (let g = 0; g < txns.length; g++) {
for (let t = 0; t < txns[g].length; t++) {
binaryTxns.push(decodeUnsignedTransaction(txns[g][t].blob).toByte())
unsignedTxns.push(txns[g][t])

const txnArray = txns[g]

if (!txnArray) {
throw new Error('Failed to parse transaction array.')
}

for (let t = 0; t < txnArray.length; t++) {

const txn = txnArray[t]

if (!txn) {
throw new Error('Failed to parse transaction array.')
}

binaryTxns.push(decodeUnsignedTransaction(txn.blob).toByte())
unsignedTxns.push(txn)
}
}

const signedTxns = await myAlgo.signTransaction(binaryTxns)

if (signedTxns.length > 0) {
return signedTxns.map((txn, i) => {

const unsignedTxn = unsignedTxns[i]

if (!unsignedTxn) {
throw new Error('Failed to parse transaction array.')
}

return {
blob: new Uint8Array(Buffer.from(txn.blob.buffer)),
txID: unsignedTxns[i].txID,
signers: unsignedTxns[i].signers
txID: unsignedTxn.txID,
signers: unsignedTxn.signers
}
})
} else {
Expand Down
29 changes: 25 additions & 4 deletions src/pera/signTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,22 @@ export default async function sign ({ pera }: Provider, txns: Array<Array<Txn>>)
let formatedTxns: Array<Array<{ txn: Transaction, signers?: Array<string> }>> = []

for (let g = 0; g < txns.length; g++) {
for (let t = 0; t < txns[g].length; t++) {
unsignedTxns.push(txns[g][t])

const txnArray = txns[g]

if (!txnArray) {
throw new Error('Failed to parse transaction array.')
}

for (let t = 0; t < txnArray.length; t++) {

const txn = txnArray[t]

if (!txn) {
throw new Error('Failed to parse transaction array.')
}

unsignedTxns.push(txn)
}
}

Expand All @@ -29,10 +43,17 @@ export default async function sign ({ pera }: Provider, txns: Array<Array<Txn>>)

if (signedTxns.length > 0) {
return signedTxns.map((txn, i) => {

const unsignedTxn = unsignedTxns[i]

if (!unsignedTxn) {
throw new Error('Failed to parse transaction array.')
}

return {
blob: txn,
txID: unsignedTxns[i].txID,
signers: unsignedTxns[i].signers
txID: unsignedTxn.txID,
signers: unsignedTxn.signers
}
})
} else {
Expand Down
26 changes: 19 additions & 7 deletions src/signTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,22 @@ export default async function signTxns (provider: Provider, txns: Array<Array<Tx

let wallet: Wallets | null = null

for (let t = 0; t < txns[i].length; t++) {
const txnArray = txns[i]

if (!wallet && txns[i][t].signers.length > 0) {
const foundAddress = provider.addresses.find((a) => a.address === txns[i][t].signers[0])
if (!txnArray) {
throw new Error('Failed to parse transaction array.')
}

for (let t = 0; t < txnArray.length; t++) {

const txn = txnArray[t]

if (!txn) {
throw new Error('Failed to parse transaction array.')
}

if (!wallet && txn.signers.length > 0) {
const foundAddress = provider.addresses.find((a) => a.address === txn.signers[0])

if (foundAddress) {
wallet = foundAddress.wallet
Expand All @@ -37,16 +49,16 @@ export default async function signTxns (provider: Provider, txns: Array<Array<Tx

switch (wallet) {
case Wallets.MYALGO:
myAlgoTxns.push(txns[i])
myAlgoTxns.push(txnArray)
break
case Wallets.PERA:
peraTxns.push(txns[i])
peraTxns.push(txnArray)
break
case Wallets.ALGOSIGNER:
algoSignerTxns.push(txns[i])
algoSignerTxns.push(txnArray)
break
case Wallets.EXODUS:
exodusTxns.push(txns[i])
exodusTxns.push(txnArray)
break
}
}
Expand Down
7 changes: 0 additions & 7 deletions tsconfig-cjs.json

This file was deleted.

8 changes: 0 additions & 8 deletions tsconfig-esm.json

This file was deleted.

4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
"noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
Expand Down Expand Up @@ -90,7 +90,7 @@
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
"noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
Expand Down

0 comments on commit 5b38953

Please sign in to comment.