-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
108 changed files
with
6,847 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ node_modules | |
*/**/build | ||
*/**/.docusaurus | ||
/lib/ | ||
*/**/lib | ||
|
||
# misc | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const parentConfig = require("../../babel.config"); | ||
|
||
module.exports = { | ||
...parentConfig, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
47
@stellar/typescript-wallet-sdk-km/src/Handlers/freighter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}.`, | ||
); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
@stellar/typescript-wallet-sdk-km/src/Handlers/plaintextKey.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}; |
Oops, something went wrong.