From baee7afc70029eb24e7ce0445e7e43b535a02e79 Mon Sep 17 00:00:00 2001 From: Iveta Date: Fri, 8 Dec 2023 17:22:28 -0500 Subject: [PATCH] Update stellar-sdk + remove soroban-client --- package.json | 3 +- src/actions/xdrViewer.js | 20 +++--- src/components/TxSubmitterResult.tsx | 12 ++-- src/constants/network.js | 3 +- src/helpers/Libify.js | 8 +-- src/helpers/extrapolateFromXdr.js | 16 ++--- src/helpers/validateTxXdr.ts | 6 +- src/views/TransactionSigner.tsx | 19 ++---- src/views/XdrViewer.tsx | 4 +- yarn.lock | 92 +++++++++------------------- 10 files changed, 66 insertions(+), 117 deletions(-) diff --git a/package.json b/package.json index e0f8986d..1d0ef4eb 100644 --- a/package.json +++ b/package.json @@ -64,8 +64,7 @@ "regenerator-runtime": "^0.13.9", "route-recognizer": "^0.3.4", "solar-stellarorg": "git+https://github.com/stellar/solar-stellarorg#master", - "soroban-client": "^1.0.0-beta.2", - "stellar-sdk": "^11.0.0-beta.4", + "stellar-sdk": "^11.0.0-beta.6", "typescript": "^4.5.5", "uri-templates": "^0.2.0", "urijs": "^1.16.0" diff --git a/src/actions/xdrViewer.js b/src/actions/xdrViewer.js index 211c2775..27d9e303 100644 --- a/src/actions/xdrViewer.js +++ b/src/actions/xdrViewer.js @@ -1,5 +1,4 @@ import * as StellarSdk from "stellar-sdk"; -import * as SorobanSdk from "soroban-client"; import axios from "axios"; import { FETCH_SEQUENCE_FAIL } from "actions/transactionBuilder"; import { SIGNATURE } from "../constants/signature"; @@ -44,12 +43,13 @@ export function fetchSigners( networkPassphrase, isSoroban = false, ) { - const sdk = isSoroban ? SorobanSdk : StellarSdk; - return (dispatch) => { dispatch({ type: FETCHED_SIGNERS.PENDING }); try { - let tx = new sdk.TransactionBuilder.fromXDR(input, networkPassphrase); + let tx = new StellarSdk.TransactionBuilder.fromXDR( + input, + networkPassphrase, + ); // Extract all source accounts from transaction (base transaction, and all operations) let sourceAccounts = {}; @@ -58,7 +58,7 @@ export function fetchSigners( // inner signatures in a fee bump transaction let groupedSignatures = []; - if (tx instanceof sdk.FeeBumpTransaction) { + if (tx instanceof StellarSdk.FeeBumpTransaction) { sourceAccounts[ convertMuxedAccountToEd25519Account(tx.feeSource) ] = true; @@ -117,12 +117,16 @@ export function fetchSigners( // tx hash in signatures array, so we can ignore pre-authorized transactions here. switch (signer.type) { case "sha256_hash": - const hashXSigner = sdk.StrKey.decodeSha256Hash(signer.key); - const hashXSignature = sdk.hash(sigObj.sig); + const hashXSigner = StellarSdk.StrKey.decodeSha256Hash( + signer.key, + ); + const hashXSignature = StellarSdk.hash(sigObj.sig); isValid = hashXSigner.equals(hashXSignature); break; case "ed25519_public_key": - const keypair = sdk.Keypair.fromPublicKey(signer.key); + const keypair = StellarSdk.Keypair.fromPublicKey( + signer.key, + ); isValid = keypair.verify(txHash, sigObj.sig); break; } diff --git a/src/components/TxSubmitterResult.tsx b/src/components/TxSubmitterResult.tsx index e518b63a..69d752bd 100644 --- a/src/components/TxSubmitterResult.tsx +++ b/src/components/TxSubmitterResult.tsx @@ -1,6 +1,5 @@ import { useReducer } from "react"; import { - Server, TransactionBuilder, AccountRequiresMemoError, BadResponseError, @@ -29,7 +28,10 @@ const initialState = { const reducer = ( state: any, - action: { type: ACTIONS; payload?: Horizon.SubmitTransactionResponse }, + action: { + type: ACTIONS; + payload?: Horizon.HorizonApi.SubmitTransactionResponse; + }, ) => { switch (action.type) { case ACTIONS.submit: @@ -83,7 +85,9 @@ export const TxSubmitterResult = ({ txXdr, networkPassphrase, ); - const server = new Server(horizonURL, { appName: "Laboratory" }); + const server = new Horizon.Server(horizonURL, { + appName: "Laboratory", + }); server.submitTransaction(transaction).then( (res) => { dispatch({ type: ACTIONS.success, payload: res }); @@ -123,7 +127,7 @@ const Response = ({ result_xdr, result_meta_xdr, fee_meta_xdr, -}: ResponseProps & Horizon.TransactionResponse) => ( +}: ResponseProps & Horizon.HorizonApi.TransactionResponse) => (

{ addedSigs++; - newTx.sign(sdk.Keypair.fromSecret(signer)); + newTx.sign(Sdk.Keypair.fromSecret(signer)); }); each(validPreimages, (signer) => { addedSigs++; diff --git a/src/helpers/extrapolateFromXdr.js b/src/helpers/extrapolateFromXdr.js index 9af48a27..1f1b4b5f 100644 --- a/src/helpers/extrapolateFromXdr.js +++ b/src/helpers/extrapolateFromXdr.js @@ -10,7 +10,6 @@ // - object: typed values always with a type and value `{type: 'code', value: 'Foo();'}` import * as StellarSdk from "stellar-sdk"; -import * as SorobanSdk from "soroban-client"; import isArray from "lodash/isArray"; import isString from "lodash/isString"; import functionsIn from "lodash/functionsIn"; @@ -22,17 +21,10 @@ export default function extrapolateFromXdr(input, type, isSoroban = false) { // TODO: input validation let xdr, StrKey, Keypair, Operation; - if (isSoroban) { - xdr = SorobanSdk.xdr; - StrKey = SorobanSdk.StrKey; - Keypair = SorobanSdk.Keypair; - Operation = SorobanSdk.Operation; - } else { - xdr = StellarSdk.xdr; - StrKey = StellarSdk.StrKey; - Keypair = StellarSdk.Keypair; - Operation = StellarSdk.Operation; - } + xdr = StellarSdk.xdr; + StrKey = StellarSdk.StrKey; + Keypair = StellarSdk.Keypair; + Operation = StellarSdk.Operation; function buildTreeFromObject(object, anchor, name) { anchor.type = name; diff --git a/src/helpers/validateTxXdr.ts b/src/helpers/validateTxXdr.ts index a1a70742..1fe8f430 100644 --- a/src/helpers/validateTxXdr.ts +++ b/src/helpers/validateTxXdr.ts @@ -1,13 +1,9 @@ import trim from "lodash/trim"; import * as StellarSdk from "stellar-sdk"; -import * as SorobanSdk from "soroban-client"; import { validateBase64 } from "./validateBase64"; -export const validateTxXdr = (input: string, isSoroban = false) => { +export const validateTxXdr = (input: string) => { let xdr = StellarSdk.xdr; - if (isSoroban) { - xdr = SorobanSdk.xdr; - } input = trim(input); let base64Validation = validateBase64(input); diff --git a/src/views/TransactionSigner.tsx b/src/views/TransactionSigner.tsx index 60fb42ab..3bb979b5 100644 --- a/src/views/TransactionSigner.tsx +++ b/src/views/TransactionSigner.tsx @@ -1,6 +1,5 @@ import { useDispatch } from "react-redux"; import * as StellarSdk from "stellar-sdk"; -import * as SorobanSdk from "soroban-client"; import { isConnected } from "@stellar/freighter-api"; import isUndefined from "lodash/isUndefined"; import map from "lodash/map"; @@ -44,16 +43,10 @@ export const TransactionSigner = () => { const networkPassphrase = network.current.networkPassphrase; const isSoroban = useIsSoroban(); - let TransactionBuilder, FeeBumpTransaction, Networks; - if (isSoroban) { - TransactionBuilder = SorobanSdk.TransactionBuilder; - FeeBumpTransaction = SorobanSdk.FeeBumpTransaction; - Networks = SorobanSdk.Networks; - } else { - TransactionBuilder = StellarSdk.TransactionBuilder; - FeeBumpTransaction = StellarSdk.FeeBumpTransaction; - Networks = StellarSdk.Networks; - } + let TransactionBuilder, FeeBumpTransaction, Networks: any; + TransactionBuilder = StellarSdk.TransactionBuilder; + FeeBumpTransaction = StellarSdk.FeeBumpTransaction; + Networks = StellarSdk.Networks; const { xdr, @@ -65,7 +58,7 @@ export const TransactionSigner = () => { } = transactionSigner; let content; - if (validateTxXdr(xdr, isSoroban).result !== "success") { + if (validateTxXdr(xdr).result !== "success") { content = (
@@ -389,7 +382,7 @@ export const TransactionSigner = () => { dispatch(setSecrets(value))} + onUpdate={(value) => dispatch(setSecrets(value))} /> diff --git a/src/views/XdrViewer.tsx b/src/views/XdrViewer.tsx index ebffd80a..93460841 100644 --- a/src/views/XdrViewer.tsx +++ b/src/views/XdrViewer.tsx @@ -1,6 +1,5 @@ import { useDispatch } from "react-redux"; import * as StellarSdk from "stellar-sdk"; -import * as SorobanSdk from "soroban-client"; import debounce from "lodash/debounce"; import functions from "lodash/functions"; import indexOf from "lodash/indexOf"; @@ -33,10 +32,9 @@ export const XdrViewer = () => { const { fetchedSigners, input, type } = xdrViewer; const { horizonURL, networkPassphrase } = network.current; const isSoroban = useIsSoroban(); - const sdk = isSoroban ? SorobanSdk : StellarSdk; // Array of all the xdr types. Then, the most common ones appear at the top // again for convenience - let xdrTypes = functions(sdk.xdr).sort(); + let xdrTypes = functions(StellarSdk.xdr).sort(); xdrTypes = [ "TransactionEnvelope", "TransactionResult", diff --git a/yarn.lock b/yarn.lock index 3ab0ae8f..3d09676d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2597,11 +2597,30 @@ resolved "https://registry.yarnpkg.com/@stellar/freighter-api/-/freighter-api-1.4.0.tgz#f53ab58792733caa1fe33d60050ec24164e331f3" integrity sha512-/ANu1/4mnReUvrSDveKj5XhrnafEssESF/lVdOR1v0ja02kFuhsdsw3anzdz0NvPaPbFgPmjU+v9t9R8KN6r+g== +"@stellar/js-xdr@^3.0.1": + version "3.0.1" + resolved "https://registry.yarnpkg.com/@stellar/js-xdr/-/js-xdr-3.0.1.tgz#d500f1e1332210cd56e0ef95e44c54506d9f48f3" + integrity sha512-dp5Eh7Nr1YjiIeqpdkj2cQYxfoPudDAH3ck8MWggp48Htw66Z/hUssNYUQG/OftLjEmHT90Z/dtey2Y77DOxIw== + "@stellar/prettier-config@^1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@stellar/prettier-config/-/prettier-config-1.0.1.tgz#498a66dc13c66859e3787dabdf958233ddbe9253" integrity sha512-w9OPycQp1XGfmHC2VUHe5shpZjNFRlmsRBaK7IHvOvVpglzV2QNJsVFh8RdLREWA0mzF59AWvQbyUCCJLPfdWw== +"@stellar/stellar-base@10.0.0": + version "10.0.0" + resolved "https://registry.yarnpkg.com/@stellar/stellar-base/-/stellar-base-10.0.0.tgz#b9ef7e84e644d06ec08b8ba88ad6b38da7b80494" + integrity sha512-zHlGzWefiB2gkt13l+I8Dvo2k7+n6+vxizay4lDEc5si0zjSZbCUUzMIdVIQ86dao7+TvZ3aNw8CdncOWLDu2A== + dependencies: + "@stellar/js-xdr" "^3.0.1" + base32.js "^0.1.0" + bignumber.js "^9.1.2" + buffer "^6.0.3" + sha.js "^2.3.6" + tweetnacl "^1.0.3" + optionalDependencies: + sodium-native "^4.0.1" + "@stellar/tsconfig@^1.0.2": version "1.0.2" resolved "https://registry.yarnpkg.com/@stellar/tsconfig/-/tsconfig-1.0.2.tgz#18e9b1a1d6076e116bb405d11fc034401155292d" @@ -4007,19 +4026,10 @@ axios@^0.25.0: dependencies: follow-redirects "^1.14.7" -axios@^1.4.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.4.0.tgz#38a7bf1224cd308de271146038b551d725f0be1f" - integrity sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA== - dependencies: - follow-redirects "^1.15.0" - form-data "^4.0.0" - proxy-from-env "^1.1.0" - -axios@^1.5.1: - version "1.5.1" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.5.1.tgz#11fbaa11fc35f431193a9564109c88c1f27b585f" - integrity sha512-Q28iYCWzNHjAm+yEAot5QaAMxhMghWLFVf7rRdwhUI+c2jix2DUXjAHXVi+s1ibs3mjPO/cCgbA++3BjD0vP/A== +axios@^1.6.0: + version "1.6.2" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.2.tgz#de67d42c755b571d3e698df1b6504cde9b0ee9f2" + integrity sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A== dependencies: follow-redirects "^1.15.0" form-data "^4.0.0" @@ -9222,11 +9232,6 @@ js-levenshtein@^1.1.6: resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== -js-xdr@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/js-xdr/-/js-xdr-3.0.0.tgz#fb74275de0ed3cec61269721140a576edf6fca7e" - integrity sha512-tSt6UKJ2L7t+yaQURGkHo9kop9qnVbChTlCu62zNiDbDZQoZb/YjUj2iFJ3lgelhfg9p5bhO2o/QX+g36TPsSQ== - js-yaml@4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" @@ -13195,17 +13200,6 @@ sodium-native@^4.0.1: version "0.2.0" resolved "git+https://github.com/stellar/solar-stellarorg#78ce86e856d21e77fab77b3767c1a224bfb7e9fe" -soroban-client@^1.0.0-beta.2: - version "1.0.0-beta.2" - resolved "https://registry.yarnpkg.com/soroban-client/-/soroban-client-1.0.0-beta.2.tgz#a59f9bd88436d6f06f38213efc4547676bee70d1" - integrity sha512-v5h3yvef7HkUD3H26w33NUEgRXcPiOSDWEsVzMloaxsprs3N002tXJHvFF+Uw1eYt50Uk6bvqBgvkLwX10VENw== - dependencies: - axios "^1.4.0" - bignumber.js "^9.1.1" - buffer "^6.0.3" - stellar-base v10.0.0-beta.1 - urijs "^1.19.1" - sort-keys@^1.0.0: version "1.1.2" resolved "https://registry.yarnpkg.com/sort-keys/-/sort-keys-1.1.2.tgz#441b6d4d346798f1b4e49e8920adfba0e543f9ad" @@ -13400,44 +13394,16 @@ statuses@~1.4.0: resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.4.0.tgz#bb73d446da2796106efcc1b601a253d6c46bd087" integrity sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew== -stellar-base@10.0.0-beta.2: - version "10.0.0-beta.2" - resolved "https://registry.yarnpkg.com/stellar-base/-/stellar-base-10.0.0-beta.2.tgz#36452bb14a7a9e66175e6231feb64de3d2fe3627" - integrity sha512-fgVcNzlGuXTte4gEg3fDA/pJB5VbqfE8+gkbjsphVecDELR8t3K+QalbDhcafi3g54nRYUaHnN7LcGeoschuIA== - dependencies: - base32.js "^0.1.0" - bignumber.js "^9.1.2" - buffer "^6.0.3" - js-xdr "^3.0.0" - sha.js "^2.3.6" - tweetnacl "^1.0.3" - optionalDependencies: - sodium-native "^4.0.1" - -stellar-base@v10.0.0-beta.1: - version "10.0.0-beta.1" - resolved "https://registry.yarnpkg.com/stellar-base/-/stellar-base-10.0.0-beta.1.tgz#5b4209fbc44b8af82dd3ee8b7f6f4397126d8c3b" - integrity sha512-zXC5AsbUsLi57JruyeIMv23s3iUxq/P2ZFrSJ+FerLIZjSAjY8EDs4zwY4LCuu7swUu46Lm8GK6sqxUZCPekHw== - dependencies: - base32.js "^0.1.0" - bignumber.js "^9.1.2" - buffer "^6.0.3" - js-xdr "^3.0.0" - sha.js "^2.3.6" - tweetnacl "^1.0.3" - optionalDependencies: - sodium-native "^4.0.1" - -stellar-sdk@^11.0.0-beta.4: - version "11.0.0-beta.4" - resolved "https://registry.yarnpkg.com/stellar-sdk/-/stellar-sdk-11.0.0-beta.4.tgz#aa79beb9a636bc4c8f4069c35248e8b1a46526df" - integrity sha512-Okq3LzpTOOLxYMyAhkdhzo1OwsPO6kVZGtxkqYApqOpSjzCDtXje9b1YGO7NycRH4ICJftxQ6TF+VZEaBvXRlQ== +stellar-sdk@^11.0.0-beta.6: + version "11.0.1" + resolved "https://registry.yarnpkg.com/stellar-sdk/-/stellar-sdk-11.0.1.tgz#de53748d648e732d0d8a3fdcb292b18e30a217cc" + integrity sha512-uRXK9NcsJNoo7F2P3JQRY9GC9+LFVQQjz9N5nmsLdUDrOT9cM8bb3MoUt9jdY5+nBsrEVnuJTZzLG29GyowBew== dependencies: - axios "^1.5.1" + "@stellar/stellar-base" "10.0.0" + axios "^1.6.0" bignumber.js "^9.1.2" eventsource "^2.0.2" randombytes "^2.1.0" - stellar-base "10.0.0-beta.2" toml "^3.0.0" urijs "^1.19.1"