Skip to content

Commit

Permalink
Release/1.4.0 (#108)
Browse files Browse the repository at this point in the history
* fix broken test (#93)

* add sep10 sign challenge txn helper (#95)

* add sep10 helper method

* name change

* correct resp

* create server module

* add npm publish gha (#96)

* WAL-1064 - add anchor platform integration tests (#99)

* create workspace (#101)

* create workspace

* try

* try

* try

* try

* cleanup

* update anchor platform docker run

* fix

* fix

* upgrade babel/traverse

* upgrade browserify-sign

* add keypair package in a second workspace (#102)

* add km package

* fix tests

* cleanup

* add second CD (#109)

* fix stellar-sdk imports (#112)

* fix imports

* fix

* preparing for 1.4.0 release stuff (#110)

* fix

* fix webpack process

* webpack fix (#113)

* webpack fix

* cleanup

* add helper for parsing AnchorTransaction (#111)

* add helper for parsing AnchorTransaction

* use kind

* add try-catch

---------

Co-authored-by: Alec Charbonneau <aleccharb21@gmail.com>
  • Loading branch information
piyalbasu and acharb committed Mar 26, 2024
1 parent a876f3b commit 360f796
Show file tree
Hide file tree
Showing 108 changed files with 6,847 additions and 217 deletions.
12 changes: 9 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ module.exports = {
ignorePatterns: ["lib/", "node_modules/", "docs/"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["tsconfig.json", "examples/tsconfig.json", "test/tsconfig.json"],
project: [
"@stellar/typescript-wallet-sdk/examples/tsconfig.json",
"@stellar/typescript-wallet-sdk/tsconfig.json",
"@stellar/typescript-wallet-sdk/test/tsconfig.json",
"@stellar/typescript-wallet-sdk-km/tsconfig.json",
"@stellar/typescript-wallet-sdk-km/test/tsconfig.json",
],
sourceType: "module",
},
plugins: ["@typescript-eslint", "jsdoc"],
Expand All @@ -24,6 +30,7 @@ module.exports = {
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-base-to-string": "off",
"jsdoc/check-indentation": "off",

// Warn
"jsdoc/check-param-names": "warn",
Expand Down Expand Up @@ -62,11 +69,10 @@ module.exports = {
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "error",
"jsdoc/check-alignment": "error",
"jsdoc/check-indentation": "error",
},
overrides: [
{
files: ["test/**", "examples/**"],
files: ["**/test/**", "@stellar/typescript-wallet-sdk/examples/**"],
rules: {
"@typescript-eslint/no-shadow": "off",
"@typescript-eslint/no-explicit-any": "off",
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/integration.anchorPlatformTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Run Test
on: [pull_request]
jobs:
test-ci:
name: anchor platform test
runs-on: ubuntu-latest
steps:
- name: Checkout Java Anchor SDK
uses: actions/checkout@v2
with:
repository: stellar/java-stellar-anchor-sdk
- name: Build docker
run:
docker build --build-arg BASE_IMAGE=gradle:7.6.4-jdk11 -t
anchor-platform:local ./
- name: Run docker
run:
docker-compose -f
service-runner/src/main/resources/docker-compose.yaml up -d
- name: Wait for docker to be ready
run: sleep 90 && curl http://localhost:8080/.well-known/stellar.toml
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 18
- run: yarn install
- run: yarn test:anchorplatform:ci
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ name: Recovery Signer Integration Test
on: [pull_request]
jobs:
test-ci:
name: integration test
name: recovery test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Start docker
run: docker-compose -f test/docker/docker-compose.yml up -d
run:
docker-compose -f
@stellar/typescript-wallet-sdk/test/docker/docker-compose.yml up -d
- uses: actions/setup-node@v2
with:
node-version: 18
- run: yarn install
- run: yarn build
- run: yarn test:integration:ci
- run: yarn test:recovery:ci
- name: Print Docker Logs
if: always() # This ensures that the logs are printed even if the tests fail
run: docker-compose -f test/docker/docker-compose.yml logs
run:
docker-compose -f
@stellar/typescript-wallet-sdk/test/docker/docker-compose.yml logs
22 changes: 22 additions & 0 deletions .github/workflows/npmPublishSdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: npm publish wallet sdk
on:
release:
types: [workflow_dispatch]
jobs:
npm-publish:
name: npm-publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- run: yarn install
- run: yarn build
- run: yarn test:ci

- name: Publish to NPM
run: cd @stellar/typescript-wallet-sdk && yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/npmPublishSdkKM.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: npm publish wallet sdk Key Manager
on:
release:
types: [workflow_dispatch]
jobs:
npm-publish:
name: npm-publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- run: yarn install
- run: yarn build
- run: yarn test:ci

- name: Publish to NPM
run:
cd @stellar/typescript-wallet-sdk-km && yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_modules
*/**/build
*/**/.docusaurus
/lib/
*/**/lib

# misc
.DS_Store
Expand Down
5 changes: 5 additions & 0 deletions @stellar/typescript-wallet-sdk-km/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const parentConfig = require("../../babel.config");

module.exports = {
...parentConfig,
};
54 changes: 54 additions & 0 deletions @stellar/typescript-wallet-sdk-km/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@stellar/typescript-wallet-sdk-km",
"version": "1.0.0",
"engines": {
"node": ">=18"
},
"browser": "./lib/bundle_browser.js",
"main": "./lib/bundle.js",
"types": "./lib/index.d.ts",
"license": "Apache-2.0",
"private": false,
"devDependencies": {
"@babel/preset-env": "^7.24.0",
"@babel/preset-typescript": "^7.23.3",
"@stellar/prettier-config": "^1.0.1",
"@stellar/tsconfig": "^1.0.2",
"@types/jest": "^29.5.12",
"@typescript-eslint/parser": "^7.1.1",
"babel-jest": "^29.7.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"jest-mock-random": "^1.1.1",
"node-localstorage": "^3.0.5",
"npm-run-all": "^4.1.5",
"sinon": "^17.0.1",
"ts-jest": "^29.1.2",
"ts-loader": "^9.5.1",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"webpack": "^5.90.3",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@albedo-link/intent": "^0.12.0",
"@ledgerhq/hw-app-str": "^6.28.4",
"@ledgerhq/hw-transport-u2f": "^5.36.0-deprecated",
"@stellar/freighter-api": "^2.0.0",
"@stellar/stellar-sdk": "^11.1.0",
"@trezor/connect-plugin-stellar": "^9.0.2",
"bignumber.js": "^9.1.2",
"scrypt-async": "^2.0.1",
"trezor-connect": "^8.2.12",
"tweetnacl": "^1.0.3",
"tweetnacl-util": "^0.15.1"
},
"scripts": {
"prepare": "husky install",
"test": "jest --watchAll",
"test:ci": "jest --ci",
"build:web": "webpack --config webpack.config.js",
"build:node": "webpack --env NODE=true --config webpack.config.js",
"build": "run-p build:web build:node"
}
}
49 changes: 49 additions & 0 deletions @stellar/typescript-wallet-sdk-km/src/Handlers/albedo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import albedo from "@albedo-link/intent";
import {
Networks,
Transaction,
TransactionBuilder,
} from "@stellar/stellar-sdk";

import {
HandlerSignTransactionParams,
KeyTypeHandler,
KeyType,
} from "../Types";

export const albedoHandler: KeyTypeHandler = {
keyType: KeyType.albedo,
async signTransaction(params: HandlerSignTransactionParams) {
const { transaction, key } = params;

if (key.privateKey !== "") {
throw new Error(
`Non-ledger key sent to ledger handler: ${JSON.stringify(
key.publicKey,
)}`,
);
}

try {
const xdr = transaction.toXDR();
const response = await albedo.tx({ xdr });

if (!response.signed_envelope_xdr) {
throw new Error("We couldn’t sign the transaction with Albedo.");
}

// fromXDR() returns type "Transaction | FeeBumpTransaction" and
// signTransaction() doesn't like "| FeeBumpTransaction" type, so casting
// to "Transaction" type.
return TransactionBuilder.fromXDR(
response.signed_envelope_xdr,
Networks.PUBLIC,
) as Transaction;
} catch (error) {
const errorMsg = error.toString();
throw new Error(
`We couldn’t sign the transaction with Albedo. ${errorMsg}.`,
);
}
},
};
47 changes: 47 additions & 0 deletions @stellar/typescript-wallet-sdk-km/src/Handlers/freighter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import freighterApi from "@stellar/freighter-api";
import {
Networks,
Transaction,
TransactionBuilder,
} from "@stellar/stellar-sdk";

import {
HandlerSignTransactionParams,
KeyTypeHandler,
KeyType,
} from "../Types";

export const freighterHandler: KeyTypeHandler = {
keyType: KeyType.freighter,
async signTransaction(params: HandlerSignTransactionParams) {
const { transaction, key, custom } = params;

if (key.privateKey !== "") {
throw new Error(
`Non-ledger key sent to ledger handler: ${JSON.stringify(
key.publicKey,
)}`,
);
}

try {
const response = await freighterApi.signTransaction(
transaction.toXDR(),
custom && custom.network ? custom.network : undefined,
);

// fromXDR() returns type "Transaction | FeeBumpTransaction" and
// signTransaction() doesn't like "| FeeBumpTransaction" type, so casting
// to "Transaction" type.
return TransactionBuilder.fromXDR(
response,
Networks.PUBLIC,
) as Transaction;
} catch (error) {
const errorMsg = error.toString();
throw new Error(
`We couldn’t sign the transaction with Freighter. ${errorMsg}.`,
);
}
},
};
6 changes: 6 additions & 0 deletions @stellar/typescript-wallet-sdk-km/src/Handlers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from "./albedo";
export * from "./freighter";
export * from "./ledger";
export * from "./plaintextKey";
// TODO - fix trezor errors
// export * from "./trezor";
47 changes: 47 additions & 0 deletions @stellar/typescript-wallet-sdk-km/src/Handlers/ledger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import LedgerStr from "@ledgerhq/hw-app-str";
import LedgerTransport from "@ledgerhq/hw-transport-u2f";
import { Keypair, xdr } from "@stellar/stellar-sdk";

import {
HandlerSignTransactionParams,
KeyTypeHandler,
KeyType,
} from "../Types";

export const ledgerHandler: KeyTypeHandler = {
keyType: KeyType.ledger,
async signTransaction(params: HandlerSignTransactionParams) {
const { transaction, key } = params;

if (key.privateKey !== "") {
throw new Error(
`Non-ledger key sent to ledger handler: ${JSON.stringify(
key.publicKey,
)}`,
);
}

/*
There's a naive way to do this (to keep all functions stateless and
make the connection anew each time), and there's some way of weaving state
into this.
Gonna do the naive thing first and then figure out how to do this right.
*/
const transport = await LedgerTransport.create(60 * 1000);
const ledgerApi = new LedgerStr(transport);
const result = await ledgerApi.signTransaction(
key.path,
transaction.signatureBase(),
);

const keyPair = Keypair.fromPublicKey(key.publicKey);
const decoratedSignature = new xdr.DecoratedSignature({
hint: keyPair.signatureHint(),
signature: result.signature,
});
transaction.signatures.push(decoratedSignature);

return Promise.resolve(transaction);
},
};
36 changes: 36 additions & 0 deletions @stellar/typescript-wallet-sdk-km/src/Handlers/plaintextKey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Keypair } from "@stellar/stellar-sdk";

import {
HandlerSignTransactionParams,
KeyTypeHandler,
KeyType,
} from "../Types";

export const plaintextKeyHandler: KeyTypeHandler = {
keyType: KeyType.plaintextKey,
signTransaction(params: HandlerSignTransactionParams) {
const { transaction, key } = params;
if (key.privateKey === "") {
throw new Error(
`Non-plaintext key sent to plaintext handler: ${JSON.stringify(
key.publicKey,
)}`,
);
}

const keyPair = Keypair.fromSecret(key.privateKey);

/*
* NOTE: we need to use the combo of getKeypairSignature() + addSignature()
* here in place of the shorter sign() call because sign() results in a
* "XDR Write Error: [object Object] is not a DecoratedSignature" error
* on React Native whenever we try to call transaction.toXDR() on the signed
* transaction.
*/

const signature = transaction.getKeypairSignature(keyPair);
transaction.addSignature(keyPair.publicKey(), signature);

return Promise.resolve(transaction);
},
};
Loading

0 comments on commit 360f796

Please sign in to comment.