diff --git a/Account.html b/Account.html index 5a3560a6..35b45628 100644 --- a/Account.html +++ b/Account.html @@ -24,7 +24,7 @@
@@ -573,7 +573,7 @@
Returns:

diff --git a/Address.html b/Address.html index f7c2e583..2c661cda 100644 --- a/Address.html +++ b/Address.html @@ -24,7 +24,7 @@
@@ -1428,7 +1428,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/Asset.html b/Asset.html index 8b77198e..fab5ef04 100644 --- a/Asset.html +++ b/Asset.html @@ -24,7 +24,7 @@
@@ -2053,7 +2053,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/Claimant.html b/Claimant.html index 1be54dc0..eb0014fa 100644 --- a/Claimant.html +++ b/Claimant.html @@ -24,7 +24,7 @@
@@ -1625,7 +1625,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/Contract.html b/Contract.html index f591f53e..9be77870 100644 --- a/Contract.html +++ b/Contract.html @@ -24,7 +24,7 @@
@@ -864,7 +864,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/ContractSpec.html b/ContractSpec.html index 2b22b42b..56ce357e 100644 --- a/ContractSpec.html +++ b/ContractSpec.html @@ -24,7 +24,7 @@
@@ -315,7 +315,7 @@

findEntrySource:
@@ -507,7 +507,7 @@

funcA
Source:
@@ -678,13 +678,11 @@

Returns:
Example
-
```js
-const args = {
+    
const args = {
   arg1: 'value1',
   arg2: 1234
 };
-const scArgs = contractSpec.funcArgsToScVals('funcName', args);
-```
+const scArgs = contractSpec.funcArgsToScVals('funcName', args);
@@ -738,7 +736,7 @@

funcRe
Source:
@@ -912,10 +910,8 @@

Returns:
Example
-
```js
-const resultScv = 'AAA=='; // Base64 encoded ScVal
-const result = contractSpec.funcResToNative('funcName', resultScv);
-```
+
const resultScv = 'AAA=='; // Base64 encoded ScVal
+const result = contractSpec.funcResToNative('funcName', resultScv);
@@ -1161,7 +1157,7 @@

nativeTo
Source:
@@ -1399,7 +1395,7 @@

scVal
Source:
@@ -1617,7 +1613,7 @@

scValToN
Source:
@@ -1804,7 +1800,7 @@

Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/FeeBumpTransaction.html b/FeeBumpTransaction.html index 4f0361b8..e423bfbc 100644 --- a/FeeBumpTransaction.html +++ b/FeeBumpTransaction.html @@ -24,7 +24,7 @@
@@ -2040,7 +2040,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/Int128_Int128.html b/Int128_Int128.html index a863533e..c15cf683 100644 --- a/Int128_Int128.html +++ b/Int128_Int128.html @@ -24,7 +24,7 @@
@@ -230,7 +230,7 @@
Parameters:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/Int256_Int256.html b/Int256_Int256.html index 373e6681..0a00e6bc 100644 --- a/Int256_Int256.html +++ b/Int256_Int256.html @@ -24,7 +24,7 @@
@@ -230,7 +230,7 @@
Parameters:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/Keypair.html b/Keypair.html index cfd8e29e..8bfa84d8 100644 --- a/Keypair.html +++ b/Keypair.html @@ -24,7 +24,7 @@
@@ -2462,7 +2462,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/LiquidityPoolAsset.html b/LiquidityPoolAsset.html index 5ef3a9b3..fc88db38 100644 --- a/LiquidityPoolAsset.html +++ b/LiquidityPoolAsset.html @@ -24,7 +24,7 @@
@@ -919,7 +919,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/LiquidityPoolId.html b/LiquidityPoolId.html index 6927c326..c7b42aaf 100644 --- a/LiquidityPoolId.html +++ b/LiquidityPoolId.html @@ -24,7 +24,7 @@
@@ -867,7 +867,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/Memo.html b/Memo.html index d30d9adf..edc76c00 100644 --- a/Memo.html +++ b/Memo.html @@ -24,7 +24,7 @@
@@ -1386,7 +1386,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/MuxedAccount.html b/MuxedAccount.html index f0e38281..b56d531e 100644 --- a/MuxedAccount.html +++ b/MuxedAccount.html @@ -24,7 +24,7 @@
@@ -985,7 +985,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/Operation.html b/Operation.html index 52987539..33871e0d 100644 --- a/Operation.html +++ b/Operation.html @@ -24,7 +24,7 @@
@@ -12124,7 +12124,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/ScInt.html b/ScInt.html index 8ddde9a5..d26e353d 100644 --- a/ScInt.html +++ b/ScInt.html @@ -24,7 +24,7 @@
@@ -486,7 +486,7 @@

Classes


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/Server.html b/Server.html index 03ad8552..e550ffef 100644 --- a/Server.html +++ b/Server.html @@ -24,7 +24,7 @@
@@ -104,7 +104,7 @@

new ServerSource:
@@ -414,7 +414,7 @@

(async) get
Source:
@@ -595,7 +595,7 @@

(async) Source:
@@ -740,7 +740,7 @@
Parameters:
-Durability +Durability @@ -769,7 +769,7 @@
Parameters:

the "durability keyspace" that this ledger key belongs to, which is either 'temporary' -or 'persistent' (the default), see Durability.

+or 'persistent' (the default), see Durability.

@@ -823,8 +823,9 @@
Example
const contractId = "CCJZ5DGASBWQXR5MPFCJXMBI333XE5U3FSJTNQU7RIKE3P5GN2K2WYD5";
 const key = xdr.ScVal.scvSymbol("counter");
-server.getContractData(contractId, key, 'temporary').then(data => {
-  console.log("value:", data.xdr);
+server.getContractData(contractId, key, Durability.Temporary).then(data => {
+  console.log("value:", data.val);
+  console.log("expirationLedgerSeq:", data.expirationLedgerSeq);
   console.log("lastModified:", data.lastModifiedLedgerSeq);
   console.log("latestLedger:", data.latestLedger);
 });
@@ -886,7 +887,7 @@

(async) getE
Source:
@@ -1081,7 +1082,7 @@

(async) getH
Source:
@@ -1208,7 +1209,7 @@

(async) Source:
@@ -1340,7 +1341,7 @@

(async) Source:
@@ -1350,6 +1351,8 @@

(async) See:
@@ -1482,7 +1485,8 @@
Example
server.getLedgerEntries([key]).then(response => { const ledgerData = response.entries[0]; console.log("key:", ledgerData.key); - console.log("value:", ledgerData.xdr); + console.log("value:", ledgerData.val); + console.log("expirationLedgerSeq:", ledgerData.expirationLedgerSeq); console.log("lastModified:", ledgerData.lastModifiedLedgerSeq); console.log("latestLedger:", response.latestLedger); }); @@ -1539,7 +1543,7 @@

(async) get
Source:
@@ -1668,7 +1672,7 @@

(async) Source:
@@ -1861,7 +1865,7 @@

(async) Source:
@@ -2163,7 +2167,7 @@

(async) Source:
@@ -2420,7 +2424,7 @@

(async) Source:
@@ -2627,7 +2631,7 @@

(async) <
Source:
@@ -2805,7 +2809,7 @@
Example

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/SignerKey.html b/SignerKey.html index 6efeccb5..4e477dcc 100644 --- a/SignerKey.html +++ b/SignerKey.html @@ -24,7 +24,7 @@
@@ -497,7 +497,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/Soroban.html b/Soroban.html index e73b078a..822bb26b 100644 --- a/Soroban.html +++ b/Soroban.html @@ -24,7 +24,7 @@
@@ -45,6 +45,9 @@

Soroban

+

Soroban +Soroban helper class to assist with formatting and parsing token amounts.

+ @@ -55,6 +58,8 @@

+

Constructor

+

new Soroban()

@@ -62,11 +67,6 @@

new Soroban -

Soroban helper class -formatting, parsing, and etc

-

- @@ -100,7 +100,7 @@

new SorobanSource:
@@ -165,9 +165,10 @@

(static) <
-

All arithmetic inside the contract is performed on integers to -avoid potential precision and consistency issues of floating-point

-

This function takes the smart contract value and its decimals (if the token has any) and returns a display value

+

Given a whole number smart contract amount of a token and an amount of +decimal places (if the token has any), it returns a "display" value.

+

All arithmetic inside the contract is performed on integers to avoid +potential precision and consistency issues of floating-point.

@@ -203,7 +204,7 @@

(static) <
Source:
@@ -310,6 +311,38 @@
Parameters:
+
+
Throws:
+ + + +
+
+
+

if the given amount has a decimal point already

+
+
+
+
+
+
+ Type +
+
+ +TypeError + + +
+
+
+
+
+ + + +
+
@@ -331,9 +364,7 @@
Returns:
-
    -
  • display value
  • -
+

the display value

@@ -341,6 +372,13 @@
Returns:
+
+
Example
+ +
formatTokenAmount("123000", 4) === "12.3";
+ +
+
@@ -355,7 +393,7 @@

(static) -

parse token amount to use it on smart contract

+

Parse a token amount to use it on smart contract

This function takes the display value and its decimals (if the token has any) and returns a string that'll be used within the smart contract.

@@ -393,7 +431,7 @@

(static) Source:
@@ -454,7 +492,8 @@
Parameters:
-

the token amount you want to use it on smart contract

+

the token amount you want to use it on smart +contract which you've been displaying in a UI

@@ -480,7 +519,9 @@
Parameters:
-

specify how many decimal places a token has

+

the number of decimal places expected in the +display value (different than the "actual" number, because suffix zeroes +might not be present)

@@ -521,9 +562,8 @@
Returns:
-
    -
  • smart contract value
  • -
+

the whole number token amount represented by the display +value with the decimal places shifted over

@@ -535,8 +575,8 @@
Returns:
Example
const displayValueAmount = "123.4560"
-const parsedAmountForSmartContract = parseTokenAmount("123.4560", 5);
-parsedAmountForSmartContract === "12345600"
+const parsedAmtForSmartContract = parseTokenAmount(displayValueAmount, 5); +parsedAmtForSmartContract === "12345600"

@@ -559,7 +599,7 @@
Example

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/SorobanDataBuilder.html b/SorobanDataBuilder.html index a5cef0b7..5ae714f8 100644 --- a/SorobanDataBuilder.html +++ b/SorobanDataBuilder.html @@ -24,7 +24,7 @@
@@ -1932,7 +1932,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/SorobanRpc.html b/SorobanRpc.html index c711520b..2a465b45 100644 --- a/SorobanRpc.html +++ b/SorobanRpc.html @@ -24,7 +24,7 @@
@@ -130,7 +130,7 @@


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/StrKey.html b/StrKey.html index df166cde..f097d7c5 100644 --- a/StrKey.html +++ b/StrKey.html @@ -24,7 +24,7 @@
@@ -3145,7 +3145,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/Transaction.html b/Transaction.html index 55ca5914..cdb10403 100644 --- a/Transaction.html +++ b/Transaction.html @@ -24,7 +24,7 @@
@@ -2960,7 +2960,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/TransactionBuilder.html b/TransactionBuilder.html index b142c268..813c3df7 100644 --- a/TransactionBuilder.html +++ b/TransactionBuilder.html @@ -24,7 +24,7 @@
@@ -3658,7 +3658,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/Uint128_Uint128.html b/Uint128_Uint128.html index 19a85f4f..6c02da95 100644 --- a/Uint128_Uint128.html +++ b/Uint128_Uint128.html @@ -24,7 +24,7 @@
@@ -230,7 +230,7 @@
Parameters:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/Uint256_Uint256.html b/Uint256_Uint256.html index 164f7f3a..a0800654 100644 --- a/Uint256_Uint256.html +++ b/Uint256_Uint256.html @@ -24,7 +24,7 @@
@@ -230,7 +230,7 @@
Parameters:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/XdrLargeInt.html b/XdrLargeInt.html index 55793d0b..8bdf62fa 100644 --- a/XdrLargeInt.html +++ b/XdrLargeInt.html @@ -24,7 +24,7 @@
@@ -1604,7 +1604,7 @@
Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/global.html b/global.html index 79cebcb4..3515c06b 100644 --- a/global.html +++ b/global.html @@ -24,7 +24,7 @@
@@ -476,15 +476,13 @@

(constant) BA
-

(constant) FastSigning

+

Durability

-

Use this flag to check if fast signing (provided by sodium-native package) is available. -If your app is signing a large number of transaction or verifying a large number -of signatures make sure sodium-native package is installed.

+

Specifies the durability namespace of contract-related ledger entries.

@@ -520,7 +518,7 @@

(constant) Source:
@@ -542,13 +540,15 @@

(constant) -

(constant) MemoHash

+

(constant) FastSigning

-

Type of Memo.

+

Use this flag to check if fast signing (provided by sodium-native package) is available. +If your app is signing a large number of transaction or verifying a large number +of signatures make sure sodium-native package is installed.

@@ -584,7 +584,7 @@

(constant) Me
Source:
@@ -606,7 +606,7 @@

(constant) Me
-

(constant) MemoID

+

(constant) MemoHash

@@ -648,7 +648,7 @@

(constant) Memo
Source:
@@ -670,7 +670,7 @@

(constant) Memo
-

(constant) MemoNone

+

(constant) MemoID

@@ -712,7 +712,7 @@

(constant) Me
Source:
@@ -734,7 +734,7 @@

(constant) Me
-

(constant) MemoReturn

+

(constant) MemoNone

@@ -776,7 +776,7 @@

(constant)
Source:
@@ -798,7 +798,7 @@

(constant)
-

(constant) MemoText

+

(constant) MemoReturn

@@ -840,7 +840,7 @@

(constant) Me
Source:
@@ -862,19 +862,13 @@

(constant) Me
-

(constant) Networks :Object

+

(constant) MemoText

-

Contains passphrases for common networks:

-
    -
  • Networks.PUBLIC: Public Global Stellar Network ; September 2015
  • -
  • Networks.TESTNET: Test SDF Network ; September 2015
  • -
  • Networks.FUTURENET: Test SDF Future Network ; October 2022
  • -
  • Networks.STANDALONE: Standalone Network ; February 2017
  • -
+

Type of Memo.

@@ -910,7 +904,7 @@

(constant) Ne
Source:
@@ -923,16 +917,6 @@

(constant) Ne -

Type:
-
    -
  • - -Object - - -
  • -
- @@ -942,13 +926,19 @@
Type:
-

SUBMIT_TRANSACTION_TIMEOUT

+

(constant) Networks :Object

-

Specifies the durability namespace of contract-related ledger entries.

+

Contains passphrases for common networks:

+
    +
  • Networks.PUBLIC: Public Global Stellar Network ; September 2015
  • +
  • Networks.TESTNET: Test SDF Network ; September 2015
  • +
  • Networks.FUTURENET: Test SDF Future Network ; October 2022
  • +
  • Networks.STANDALONE: Standalone Network ; February 2017
  • +
@@ -984,7 +974,7 @@

Source:
@@ -997,6 +987,16 @@

Type:

+
    +
  • + +Object + + +
  • +
+ @@ -1314,7 +1314,7 @@

as
Source:
@@ -1468,25 +1468,28 @@

Returns:
-

authorizeInvocation(signer, networkPassphrase, validUntil, invocation) → {xdr.SorobanAuthorizationEntry}

+

authorizeEntry(entry, signer, validUntilLedgerSeq, networkPassphraseopt) → {Promise.<xdr.SorobanAuthorizationEntry>}

-

This builds an authorization entry that indicates to -Operation.invokeHostFunction that a particular identity (i.e. signing -Keypair or other signer) approves the execution of an invocation tree -(i.e. a simulation-acquired xdr.SorobanAuthorizedInvocation) on a -particular network (uniquely identified by its passphrase, see -Networks) until a particular ledger sequence is reached.

-

This enables building an xdr.SorobanAuthorizationEntry without -worrying about how to combine buildAuthEnvelope and -buildAuthEntry, while those allow advanced, asynchronous, two-step -building+signing of the authorization entries.

-

This one lets you pass a either a Keypair or a callback function to -handle signing the envelope hash.

+

Actually authorizes an existing authorization entry using the given the +credentials and expiration details, returning a signed copy.

+

This "fills out" the authorization entry with a signature, indicating to the +Operation.invokeHostFunction its attached to that:

+
    +
  • a particular identity (i.e. signing Keypair or other signer)
  • +
  • approving the execution of an invocation tree (i.e. a simulation-acquired +xdr.SorobanAuthorizedInvocation or otherwise built)
  • +
  • on a particular network (uniquely identified by its passphrase, see +Networks)
  • +
  • until a particular ledger sequence is reached.
  • +
+

This one lets you pass a either a Keypair (or, more accurately, +anything with a sign(Buffer): Buffer method) or a callback function (see +SigningCallback) to handle signing the envelope hash.

@@ -1522,13 +1525,20 @@

au
Source:
+
See:
+
+ +
+ @@ -1554,6 +1564,8 @@

Parameters:
Type + Attributes + @@ -1566,24 +1578,32 @@
Parameters:
- signer + entry -Keypair +xdr.SorobanAuthorizationEntry + + + + + + + + -

the identity keypair authorizing this invocation

+

an unsigned authorization entr

@@ -1592,25 +1612,39 @@
Parameters:
- networkPassphrase + signer -string +Keypair +| + +SigningCallback + + + + + + + + -

the network passphrase is incorprated -into the signature (see Networks for options)

+

either a Keypair instance +or a function which takes a payload (a +xdr.HashIdPreimageSorobanAuthorization instance) input and returns +the signature of the hash of the raw payload bytes (where the signing key +should correspond to the address in the entry)

@@ -1619,7 +1653,7 @@
Parameters:
- validUntil + validUntilLedgerSeq @@ -1632,12 +1666,20 @@
Parameters:
+ + + + + + + + -

the (exclusive) future ledger sequence number -until which this authorization entry should be valid (if +

the (exclusive) future ledger sequence +number until which this authorization entry should be valid (if currentLedgerSeq==validUntil, this is expired))

@@ -1647,25 +1689,35 @@
Parameters:
- invocation + networkPassphrase -xdr.SorobanAuthorizedInvocation +string + + + <optional>
+ + + + + + + -

the invocation tree that -we're authorizing (likely, this comes from transaction simulation)

+

the network passphrase is incorprated +into the signature (see Networks for options)

@@ -1698,7 +1750,7 @@
Returns:
-xdr.SorobanAuthorizationEntry +Promise.<xdr.SorobanAuthorizationEntry>
@@ -1706,8 +1758,9 @@
Returns:
-

an authorization entry that you can -pass along to Operation.invokeHostFunction

+

a promise for an +authorization entry that you can pass along to +Operation.invokeHostFunction

@@ -1715,6 +1768,46 @@
Returns:
+
+
Example
+ +
import { Server, Transaction, Networks, authorizeEntry } from 'soroban-client';
+
+// Assume signPayloadCallback is a well-formed signing callback.
+//
+// It might, for example, pop up a modal from a browser extension, send the
+// transaction to a third-party service for signing, or just do simple
+// signing via Keypair like it does here:
+function signPayloadCallback(payload) {
+   return signer.sign(hash(payload.toXDR());
+}
+
+function multiPartyAuth(
+   server: Server,
+   // assume this involves multi-party auth
+   tx: Transaction,
+) {
+   return server
+     .simulateTransaction(tx)
+     .then((simResult) => {
+         tx.operations[0].auth.map(entry =>
+           authorizeEntry(
+             entry,
+             signPayloadCallback,
+             currentLedger + 1000,
+             Networks.FUTURENET);
+         ));
+
+         return server.prepareTransaction(tx, Networks.FUTURENET, simResult);
+     })
+     .then((preppedTx) => {
+       preppedTx.sign(source);
+       return server.sendTransaction(preppedTx);
+     });
+}
+ +
+

@@ -1722,17 +1815,24 @@
Returns:
-

authorizeInvocationCallback(publicKey, signingMethod, networkPassphrase, validUntil, invocation) → {Promise.<xdr.SorobanAuthorizationEntry>}

+

authorizeInvocation(signer, validUntilLedgerSeq, invocation, publicKeyopt, networkPassphraseopt) → {Promise.<xdr.SorobanAuthorizationEntry>}

-

This works like authorizeInvocation, but allows passing an -asynchronous callback as a "signing method" (e.g. Keypair.sign) and a -public key instead of a specific Keypair.

-

This is to make two-step authorization (i.e. custom signing flows) easier.

+

This builds an entry from scratch, allowing you to express authorization as a +function of:

+
    +
  • a particular identity (i.e. signing Keypair or other signer)
  • +
  • approving the execution of an invocation tree (i.e. a simulation-acquired +xdr.SorobanAuthorizedInvocation or otherwise built)
  • +
  • on a particular network (uniquely identified by its passphrase, see +Networks)
  • +
  • until a particular ledger sequence is reached.
  • +
+

This is in contrast to authorizeEntry, which signs an existing entry.

@@ -1768,7 +1868,7 @@

<
Source:
@@ -1778,7 +1878,7 @@

<
See:
@@ -1807,6 +1907,8 @@
Parameters:
Type + Attributes + @@ -1819,577 +1921,111 @@
Parameters:
- publicKey - - - - - -string - - - - - - - - - - -

the public identity that is authorizing this -invocation via its signature

- - - - - - - - - signingMethod - - - - - -function - - - - - - - - - - -

a function which takes -an input bytearray and returns its signature as signed by the private key -corresponding to the publicKey parameter

- - - - - - - - - networkPassphrase - - - - - -string - - - - - - - - - - -

the network passphrase is incorprated -into the signature (see Networks for options)

- - - - - - - - - validUntil - - - - - -number - - - - - - - - - - -

the (exclusive) future ledger sequence number -until which this authorization entry should be valid (if -currentLedgerSeq==validUntil, this is expired)

- - - - - - - - - invocation + signer -xdr.SorobanAuthorizedInvocation - - - - - - - - - - -

the invocation tree that -we're authorizing (likely, this comes from transaction simulation)

- - - - - - - - - - - - - - - - - - - - - -
-
Returns:
- - - -
-
- Type: -
-
- -Promise.<xdr.SorobanAuthorizationEntry> - - -
-
- - - -
- - - -

- - -
- - - -

buildAuthEntry(envelope, signature, publicKey) → {xdr.SorobanAuthorizationEntry}

- - - - - -
-

Builds an auth entry with a signed invocation tree.

-

You should first build the envelope using buildAuthEnvelope. If you -have a signing Keypair, you can use the more convenient -authorizeInvocation to do signing for you.

-
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- - - - - - - -
- - - - - - - - - -
Parameters:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
envelope - - -xdr.HashIdPreimage - - - - -

an envelope to represent the call tree -being signed, probably built by buildAuthEnvelope

- -
signature - - -Buffer -| - -Uint8Array - - - - -

a signature of the hash of the -envelope by the private key corresponding to publicKey (in other words, -signature = sign(hash(envelope)))

- -
publicKey - - -string - - - - -

the public identity that signed this envelope

- -
- - - - - - - - - - - - -
-
Throws:
-
    -
  • - -
    -
    -
    -

    if verify(hash(envelope), signature, publicKey) does not -pass, meaning one of the arguments was not passed or built correctly

    -
    -
    -
    -
    -
    -
    - Type -
    -
    - -Error - - -
    -
    -
    -
    -
    - -
  • - -
  • - -
    -
    -
    -

    if the envelope does not hold an -xdr.HashIdPreimageSorobanAuthorization instance

    -
    -
    -
    -
    -
    -
    - Type -
    -
    - -TypeError - - -
    -
    -
    -
    -
    - -
  • -
-
- - - -
-
Returns:
- - - -
-
- Type: -
-
- -xdr.SorobanAuthorizationEntry - - -
-
- - - -
- - - -
- - -
- - - -

buildAuthEnvelope(networkPassphrase, validUntil, invocation) → {xdr.HashIdPreimage}

- - - - - -
-

Builds an xdr.HashIdPreimage that, when hashed and signed, can be -used to build an xdr.SorobanAuthorizationEntry via -buildAuthEnvelope to approve Operation.invokeHostFunction -invocations.

-

The envelope built here will approve the execution of an invocation tree -(i.e. a simulation-acquired xdr.SorobanAuthorizedInvocation) on a -particular network (uniquely identified by its passphrase, see -Networks) until a particular ledger sequence is reached (exclusive).

-
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Source:
-
- +Keypair +| - +SigningCallback - - -
+ + + + + + + + + + + +

either a Keypair instance +(or anything with a .sign(buf): Buffer-like method) or a function which +takes a payload (a xdr.HashIdPreimageSorobanAuthorization +instance) input and returns the signature of the hash of the raw payload +bytes (where the signing key should correspond to the address in the +entry)

+ + + + + + + validUntilLedgerSeq + + + + +number -
Parameters:
- - - - - - - + + - + + + - - - + + + + - - + + + @@ -2398,25 +2034,36 @@
Parameters:
- + + + @@ -2425,25 +2072,36 @@
Parameters:
- + + + @@ -2476,7 +2134,7 @@
Returns:
-xdr.HashIdPreimage +Promise.<xdr.SorobanAuthorizationEntry>
@@ -2484,9 +2142,9 @@
Returns:
-

a preimage envelope that, when hashed and -signed, represents the signature necessary to build a proper -xdr.SorobanAuthorizationEntry via buildAuthEntry.

+

a promise for an +authorization entry that you can pass along to +Operation.invokeHostFunction

@@ -4674,7 +4332,7 @@

par
Source:
@@ -6381,6 +6039,168 @@

Returns:
+ + + +
+ + + +

(async) SigningCallback(preimage) → {Promise.<Uint8Array>}

+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + +
NameType + - + - + + Description
+

the (exclusive) future ledger sequence +number until which this authorization entry should be valid (if +currentLedgerSeq==validUntilLedgerSeq, this is expired))

+ +
networkPassphraseinvocation -string +xdr.SorobanAuthorizedInvocation + + + + + + -

the network passphrase is incorprated -into the signature (see Networks for options)

+

the invocation tree that +we're authorizing (likely, this comes from transaction simulation)

validUntilpublicKey -number +string + + <optional>
+ + + + + +
-

the (exclusive) future ledger sequence number -until which this authorization entry should be valid

+

the public identity of the signer (when +providing a Keypair to signer, this can be omitted, as it just +uses Keypair.publicKey)

invocationnetworkPassphrase -xdr.SorobanAuthorizedInvocation +string + + <optional>
+ + + + + +
-

the invocation tree that -we're authorizing (likely, this comes from transaction simulation)

+

the network passphrase is incorprated +into the signature (see Networks for options, default: +Networks.FUTURENET)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
preimage + + +xdr.HashIdPreimage + + + + +

the entire authorization envelope +whose hash you should sign, so that you can inspect the entire structure +if necessary (rather than blindly signing a hash)

+ +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Promise.<Uint8Array> + + +
+
+ + +
+

the signature of the raw payload (which is +the sha256 hash of the preimage bytes, so hash(preimage.toXDR())) signed +by the key corresponding to the public key in the entry you pass to +authorizeEntry (decipherable from its +credentials().address().address())

+
+ + +
+ + +
@@ -6398,7 +6218,7 @@

Returns:

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/index.html b/index.html index 5acfa0d1..560917c0 100644 --- a/index.html +++ b/index.html @@ -24,7 +24,7 @@
@@ -222,7 +222,7 @@

License


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_account.js.html b/js-stellar-base_src_account.js.html index 347e7f7f..541a1c54 100644 --- a/js-stellar-base_src_account.js.html +++ b/js-stellar-base_src_account.js.html @@ -24,7 +24,7 @@
@@ -113,7 +113,7 @@

js-stellar-base/src/account.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_address.js.html b/js-stellar-base_src_address.js.html index e0571504..16797205 100644 --- a/js-stellar-base_src_address.js.html +++ b/js-stellar-base_src_address.js.html @@ -24,7 +24,7 @@
@@ -189,7 +189,7 @@

js-stellar-base/src/address.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_asset.js.html b/js-stellar-base_src_asset.js.html index 504b1803..b1f512f4 100644 --- a/js-stellar-base_src_asset.js.html +++ b/js-stellar-base_src_asset.js.html @@ -24,7 +24,7 @@
@@ -345,7 +345,7 @@

js-stellar-base/src/asset.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_auth.js.html b/js-stellar-base_src_auth.js.html index fd6eccd1..74edba9e 100644 --- a/js-stellar-base_src_auth.js.html +++ b/js-stellar-base_src_auth.js.html @@ -24,7 +24,7 @@
@@ -41,198 +41,232 @@

js-stellar-base/src/auth.js

import xdr from './xdr';
 
-import { StrKey } from './strkey';
 import { Keypair } from './keypair';
+import { StrKey } from './strkey';
+import { Networks } from './network';
 import { hash } from './hashing';
 
 import { Address } from './address';
 import { nativeToScVal } from './scval';
 
 /**
- * This builds an authorization entry that indicates to
- * {@link Operation.invokeHostFunction} that a particular identity (i.e. signing
- * {@link Keypair} or other signer) approves the execution of an invocation tree
- * (i.e. a simulation-acquired {@link xdr.SorobanAuthorizedInvocation}) on a
- * particular network (uniquely identified by its passphrase, see
- * {@link Networks}) until a particular ledger sequence is reached.
- *
- * This enables building an {@link xdr.SorobanAuthorizationEntry} without
- * worrying about how to combine {@link buildAuthEnvelope} and
- * {@link buildAuthEntry}, while those allow advanced, asynchronous, two-step
- * building+signing of the authorization entries.
- *
- * This one lets you pass a either a {@link Keypair} or a callback function to
- * handle signing the envelope hash.
+ * @async
+ * @callback SigningCallback A callback for signing an XDR structure
+ * representing all of the details necessary to authorize an invocation tree.
  *
- * @param {Keypair} signer   the identity keypair authorizing this invocation
- * @param {string}  networkPassphrase   the network passphrase is incorprated
- *    into the signature (see {@link Networks} for options)
- * @param {number}  validUntil  the (exclusive) future ledger sequence number
- *    until which this authorization entry should be valid (if
- *    `currentLedgerSeq==validUntil`, this is expired))
- * @param {xdr.SorobanAuthorizedInvocation} invocation the invocation tree that
- *    we're authorizing (likely, this comes from transaction simulation)
+ * @param {xdr.HashIdPreimage} preimage   the entire authorization envelope
+ *    whose hash you should sign, so that you can inspect the entire structure
+ *    if necessary (rather than blindly signing a hash)
  *
- * @returns {xdr.SorobanAuthorizationEntry}  an authorization entry that you can
- *    pass along to {@link Operation.invokeHostFunction}
+ * @returns {Promise<Uint8Array>}   the signature of the raw payload (which is
+ *    the sha256 hash of the preimage bytes, so `hash(preimage.toXDR())`) signed
+ *    by the key corresponding to the public key in the entry you pass to
+ *    {@link authorizeEntry} (decipherable from its
+ *    `credentials().address().address()`)
  */
-export function authorizeInvocation(
-  signer,
-  networkPassphrase,
-  validUntil,
-  invocation
-) {
-  const preimage = buildAuthEnvelope(networkPassphrase, validUntil, invocation);
-  const input = hash(preimage.toXDR());
-  const signature = signer.sign(input);
-  return buildAuthEntry(preimage, signature, signer.publicKey());
-}
 
 /**
- * This works like {@link authorizeInvocation}, but allows passing an
- * asynchronous callback as a "signing method" (e.g. {@link Keypair.sign}) and a
- * public key instead of a specific {@link Keypair}.
+ * Actually authorizes an existing authorization entry using the given the
+ * credentials and expiration details, returning a signed copy.
  *
- * This is to make two-step authorization (i.e. custom signing flows) easier.
+ * This "fills out" the authorization entry with a signature, indicating to the
+ * {@link Operation.invokeHostFunction} its attached to that:
+ *   - a particular identity (i.e. signing {@link Keypair} or other signer)
+ *   - approving the execution of an invocation tree (i.e. a simulation-acquired
+ *     {@link xdr.SorobanAuthorizedInvocation} or otherwise built)
+ *   - on a particular network (uniquely identified by its passphrase, see
+ *     {@link Networks})
+ *   - until a particular ledger sequence is reached.
  *
- * @borrows authorizeInvocation
+ * This one lets you pass a either a {@link Keypair} (or, more accurately,
+ * anything with a `sign(Buffer): Buffer` method) or a callback function (see
+ * {@link SigningCallback}) to handle signing the envelope hash.
  *
- * @param {string} publicKey    the public identity that is authorizing this
- *    invocation via its signature
- * @param {function(Buffer): Buffer} signingMethod  a function which takes
- *    an input bytearray and returns its signature as signed by the private key
- *    corresponding to the `publicKey` parameter
- * @param {string}  networkPassphrase   the network passphrase is incorprated
+ * @param {xdr.SorobanAuthorizationEntry} entry   an unsigned authorization entr
+ * @param {Keypair | SigningCallback} signer  either a {@link Keypair} instance
+ *    or a function which takes a payload (a
+ *    {@link xdr.HashIdPreimageSorobanAuthorization} instance) input and returns
+ *    the signature of the hash of the raw payload bytes (where the signing key
+ *    should correspond to the address in the `entry`)
+ * @param {number} validUntilLedgerSeq   the (exclusive) future ledger sequence
+ *    number until which this authorization entry should be valid (if
+ *    `currentLedgerSeq==validUntil`, this is expired))
+ * @param {string} [networkPassphrase]  the network passphrase is incorprated
  *    into the signature (see {@link Networks} for options)
- * @param {number} validUntil   the (exclusive) future ledger sequence number
- *    until which this authorization entry should be valid (if
- *    `currentLedgerSeq==validUntil`, this is expired)
- * @param {xdr.SorobanAuthorizedInvocation} invocation the invocation tree that
- *    we're authorizing (likely, this comes from transaction simulation)
  *
- * @returns {Promise<xdr.SorobanAuthorizationEntry>}
+ * @returns {Promise<xdr.SorobanAuthorizationEntry>} a promise for an
+ *    authorization entry that you can pass along to
+ *    {@link Operation.invokeHostFunction}
+ *
  * @see authorizeInvocation
+ * @example
+ * import { Server, Transaction, Networks, authorizeEntry } from 'soroban-client';
+ *
+ * // Assume signPayloadCallback is a well-formed signing callback.
+ * //
+ * // It might, for example, pop up a modal from a browser extension, send the
+ * // transaction to a third-party service for signing, or just do simple
+ * // signing via Keypair like it does here:
+ * function signPayloadCallback(payload) {
+ *    return signer.sign(hash(payload.toXDR());
+ * }
+ *
+ * function multiPartyAuth(
+ *    server: Server,
+ *    // assume this involves multi-party auth
+ *    tx: Transaction,
+ * ) {
+ *    return server
+ *      .simulateTransaction(tx)
+ *      .then((simResult) => {
+ *          tx.operations[0].auth.map(entry =>
+ *            authorizeEntry(
+ *              entry,
+ *              signPayloadCallback,
+ *              currentLedger + 1000,
+ *              Networks.FUTURENET);
+ *          ));
+ *
+ *          return server.prepareTransaction(tx, Networks.FUTURENET, simResult);
+ *      })
+ *      .then((preppedTx) => {
+ *        preppedTx.sign(source);
+ *        return server.sendTransaction(preppedTx);
+ *      });
+ * }
  */
-export async function authorizeInvocationCallback(
-  publicKey,
-  signingMethod,
-  networkPassphrase,
-  validUntil,
-  invocation
+export async function authorizeEntry(
+  entry,
+  signer,
+  validUntilLedgerSeq,
+  networkPassphrase = Networks.FUTURENET
 ) {
-  const preimage = buildAuthEnvelope(networkPassphrase, validUntil, invocation);
-  const input = hash(preimage.toXDR());
-  const signature = await signingMethod(input);
-  return buildAuthEntry(preimage, signature, publicKey);
+  // no-op if it's source account auth
+  if (
+    entry.credentials().switch().value !==
+    xdr.SorobanCredentialsType.sorobanCredentialsAddress().value
+  ) {
+    return entry;
+  }
+
+  const clone = xdr.SorobanAuthorizationEntry.fromXDR(entry.toXDR());
+
+  /** @type {xdr.SorobanAddressCredentials} */
+  const addrAuth = clone.credentials().address();
+  addrAuth.signatureExpirationLedger(validUntilLedgerSeq);
+
+  const networkId = hash(Buffer.from(networkPassphrase));
+  const preimage = xdr.HashIdPreimage.envelopeTypeSorobanAuthorization(
+    new xdr.HashIdPreimageSorobanAuthorization({
+      networkId,
+      nonce: addrAuth.nonce(),
+      invocation: clone.rootInvocation(),
+      signatureExpirationLedger: addrAuth.signatureExpirationLedger()
+    })
+  );
+  const payload = hash(preimage.toXDR());
+
+  let signature;
+  if (typeof signer === 'function') {
+    signature = Buffer.from(await signer(preimage));
+  } else {
+    signature = Buffer.from(signer.sign(payload));
+  }
+  const publicKey = Address.fromScAddress(addrAuth.address()).toString();
+
+  if (!Keypair.fromPublicKey(publicKey).verify(payload, signature)) {
+    throw new Error(`signature doesn't match payload`);
+  }
+
+  // This structure is defined here:
+  // https://soroban.stellar.org/docs/fundamentals-and-concepts/invoking-contracts-with-transactions#stellar-account-signatures
+  //
+  // Encoding a contract structure as an ScVal means the map keys are supposed
+  // to be symbols, hence the forced typing here.
+  const sigScVal = nativeToScVal(
+    {
+      public_key: StrKey.decodeEd25519PublicKey(publicKey),
+      signature
+    },
+    {
+      type: {
+        public_key: ['symbol', null],
+        signature: ['symbol', null]
+      }
+    }
+  );
+
+  addrAuth.signature(xdr.ScVal.scvVec([sigScVal]));
+  return clone;
 }
 
 /**
- * Builds an {@link xdr.HashIdPreimage} that, when hashed and signed, can be
- * used to build an {@link xdr.SorobanAuthorizationEntry} via
- * {@link buildAuthEnvelope} to approve {@link Operation.invokeHostFunction}
- * invocations.
+ * This builds an entry from scratch, allowing you to express authorization as a
+ * function of:
+ *   - a particular identity (i.e. signing {@link Keypair} or other signer)
+ *   - approving the execution of an invocation tree (i.e. a simulation-acquired
+ *     {@link xdr.SorobanAuthorizedInvocation} or otherwise built)
+ *   - on a particular network (uniquely identified by its passphrase, see
+ *     {@link Networks})
+ *   - until a particular ledger sequence is reached.
  *
- * The envelope built here will approve the execution of an invocation tree
- * (i.e. a simulation-acquired {@link xdr.SorobanAuthorizedInvocation}) on a
- * particular network (uniquely identified by its passphrase, see
- * {@link Networks}) until a particular ledger sequence is reached (exclusive).
+ * This is in contrast to {@link authorizeEntry}, which signs an existing entry.
  *
- * @param {string}  networkPassphrase   the network passphrase is incorprated
- *    into the signature (see {@link Networks} for options)
- * @param {number}  validUntil the (exclusive) future ledger sequence number
- *    until which this authorization entry should be valid
+ * @param {Keypair | SigningCallback} signer  either a {@link Keypair} instance
+ *    (or anything with a `.sign(buf): Buffer-like` method) or a function which
+ *    takes a payload (a {@link xdr.HashIdPreimageSorobanAuthorization}
+ *    instance) input and returns the signature of the hash of the raw payload
+ *    bytes (where the signing key should correspond to the address in the
+ *    `entry`)
+ * @param {number}  validUntilLedgerSeq  the (exclusive) future ledger sequence
+ *    number until which this authorization entry should be valid (if
+ *    `currentLedgerSeq==validUntilLedgerSeq`, this is expired))
  * @param {xdr.SorobanAuthorizedInvocation} invocation the invocation tree that
  *    we're authorizing (likely, this comes from transaction simulation)
+ * @param {string}  [publicKey]   the public identity of the signer (when
+ *    providing a {@link Keypair} to `signer`, this can be omitted, as it just
+ *    uses {@link Keypair.publicKey})
+ * @param {string}  [networkPassphrase]   the network passphrase is incorprated
+ *    into the signature (see {@link Networks} for options, default:
+ *    {@link Networks.FUTURENET})
+ *
+ * @returns {Promise<xdr.SorobanAuthorizationEntry>} a promise for an
+ *    authorization entry that you can pass along to
+ *    {@link Operation.invokeHostFunction}
  *
- * @returns {xdr.HashIdPreimage}  a preimage envelope that, when hashed and
- *    signed, represents the signature necessary to build a proper
- *    {@link xdr.SorobanAuthorizationEntry} via {@link buildAuthEntry}.
+ * @see authorizeEntry
  */
-export function buildAuthEnvelope(networkPassphrase, validUntil, invocation) {
+export function authorizeInvocation(
+  signer,
+  validUntilLedgerSeq,
+  invocation,
+  publicKey = '',
+  networkPassphrase = Networks.FUTURENET
+) {
   // We use keypairs as a source of randomness for the nonce to avoid mucking
   // with any crypto dependencies. Note that this just has to be random and
   // unique, not cryptographically secure, so it's fine.
   const kp = Keypair.random().rawPublicKey();
   const nonce = new xdr.Int64(bytesToInt64(kp));
 
-  const networkId = hash(Buffer.from(networkPassphrase));
-  const envelope = new xdr.HashIdPreimageSorobanAuthorization({
-    networkId,
-    invocation,
-    nonce,
-    signatureExpirationLedger: validUntil
-  });
-
-  return xdr.HashIdPreimage.envelopeTypeSorobanAuthorization(envelope);
-}
-
-/**
- * Builds an auth entry with a signed invocation tree.
- *
- * You should first build the envelope using {@link buildAuthEnvelope}. If you
- * have a signing {@link Keypair}, you can use the more convenient
- * {@link authorizeInvocation} to do signing for you.
- *
- * @param {xdr.HashIdPreimage} envelope   an envelope to represent the call tree
- *    being signed, probably built by {@link buildAuthEnvelope}
- * @param {Buffer|Uint8Array} signature   a signature of the hash of the
- *    envelope by the private key corresponding to `publicKey` (in other words,
- *    `signature = sign(hash(envelope))`)
- * @param {string} publicKey  the public identity that signed this envelope
- *
- * @returns {xdr.SorobanAuthorizationEntry}
- *
- * @throws {Error} if `verify(hash(envelope), signature, publicKey)` does not
- *    pass, meaning one of the arguments was not passed or built correctly
- * @throws {TypeError} if the envelope does not hold an
- *    {@link xdr.HashIdPreimageSorobanAuthorization} instance
- */
-export function buildAuthEntry(envelope, signature, publicKey) {
-  // ensure this identity signed this envelope correctly
-  if (
-    !Keypair.fromPublicKey(publicKey).verify(hash(envelope.toXDR()), signature)
-  ) {
-    throw new Error(`signature does not match envelope or identity`);
-  }
-
-  if (
-    envelope.switch() !== xdr.EnvelopeType.envelopeTypeSorobanAuthorization()
-  ) {
-    throw new TypeError(
-      `expected sorobanAuthorization envelope, got ${envelope.switch().name}`
-    );
+  const pk = publicKey || signer.publicKey();
+  if (!pk) {
+    throw new Error(`authorizeInvocation requires publicKey parameter`);
   }
 
-  const auth = envelope.sorobanAuthorization();
-  return new xdr.SorobanAuthorizationEntry({
-    rootInvocation: auth.invocation(),
+  const entry = new xdr.SorobanAuthorizationEntry({
+    rootInvocation: invocation,
     credentials: xdr.SorobanCredentials.sorobanCredentialsAddress(
       new xdr.SorobanAddressCredentials({
-        address: new Address(publicKey).toScAddress(),
-        nonce: auth.nonce(),
-        signatureExpirationLedger: auth.signatureExpirationLedger(),
-        // This structure is defined here:
-        // https://soroban.stellar.org/docs/fundamentals-and-concepts/invoking-contracts-with-transactions#stellar-account-signatures
-        //
-        // Encoding a contract structure as an ScVal means the keys are supposed
-        // to be symbols, hence the forced typing here.
-        signature: xdr.ScVal.scvVec([
-          nativeToScVal(
-            {
-              public_key: StrKey.decodeEd25519PublicKey(publicKey),
-              signature
-            },
-            {
-              type: {
-                public_key: ['symbol', null],
-                signature: ['symbol', null]
-              }
-            }
-          )
-        ])
+        address: new Address(pk).toScAddress(),
+        nonce,
+        signatureExpirationLedger: 0, // replaced
+        signature: xdr.ScVal.scvVec([]) // replaced
       })
     )
   });
+
+  return authorizeEntry(entry, signer, validUntilLedgerSeq, networkPassphrase);
 }
 
 function bytesToInt64(bytes) {
@@ -251,7 +285,7 @@ 

js-stellar-base/src/auth.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_claimant.js.html b/js-stellar-base_src_claimant.js.html index d02450ac..f06c14a5 100644 --- a/js-stellar-base_src_claimant.js.html +++ b/js-stellar-base_src_claimant.js.html @@ -24,7 +24,7 @@
@@ -223,7 +223,7 @@

js-stellar-base/src/claimant.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_contract.js.html b/js-stellar-base_src_contract.js.html index 91a87a07..085566a9 100644 --- a/js-stellar-base_src_contract.js.html +++ b/js-stellar-base_src_contract.js.html @@ -24,7 +24,7 @@
@@ -143,7 +143,7 @@

js-stellar-base/src/contract.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_events.js.html b/js-stellar-base_src_events.js.html index 41f4b384..6861cd84 100644 --- a/js-stellar-base_src_events.js.html +++ b/js-stellar-base_src_events.js.html @@ -24,7 +24,7 @@
@@ -95,7 +95,7 @@

js-stellar-base/src/events.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_fee_bump_transaction.js.html b/js-stellar-base_src_fee_bump_transaction.js.html index cb8944fc..c3070d7b 100644 --- a/js-stellar-base_src_fee_bump_transaction.js.html +++ b/js-stellar-base_src_fee_bump_transaction.js.html @@ -24,7 +24,7 @@
@@ -166,7 +166,7 @@

js-stellar-base/src/fee_bump_transaction.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_get_liquidity_pool_id.js.html b/js-stellar-base_src_get_liquidity_pool_id.js.html index ab7d367d..53a68327 100644 --- a/js-stellar-base_src_get_liquidity_pool_id.js.html +++ b/js-stellar-base_src_get_liquidity_pool_id.js.html @@ -24,7 +24,7 @@
@@ -105,7 +105,7 @@

js-stellar-base/src/get_liquidity_pool_id.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_invocation.js.html b/js-stellar-base_src_invocation.js.html index 416b2b05..7fc3ae6c 100644 --- a/js-stellar-base_src_invocation.js.html +++ b/js-stellar-base_src_invocation.js.html @@ -24,7 +24,7 @@
@@ -249,7 +249,7 @@

js-stellar-base/src/invocation.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_keypair.js.html b/js-stellar-base_src_keypair.js.html index 76409d41..b8965e9d 100644 --- a/js-stellar-base_src_keypair.js.html +++ b/js-stellar-base_src_keypair.js.html @@ -24,7 +24,7 @@
@@ -327,7 +327,7 @@

js-stellar-base/src/keypair.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_liquidity_pool_asset.js.html b/js-stellar-base_src_liquidity_pool_asset.js.html index c551b9a8..9538c2be 100644 --- a/js-stellar-base_src_liquidity_pool_asset.js.html +++ b/js-stellar-base_src_liquidity_pool_asset.js.html @@ -24,7 +24,7 @@
@@ -171,7 +171,7 @@

js-stellar-base/src/liquidity_pool_asset.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_liquidity_pool_id.js.html b/js-stellar-base_src_liquidity_pool_id.js.html index b83794f2..9e62eae9 100644 --- a/js-stellar-base_src_liquidity_pool_id.js.html +++ b/js-stellar-base_src_liquidity_pool_id.js.html @@ -24,7 +24,7 @@
@@ -128,7 +128,7 @@

js-stellar-base/src/liquidity_pool_id.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_memo.js.html b/js-stellar-base_src_memo.js.html index 01d685fc..a72e1c3b 100644 --- a/js-stellar-base_src_memo.js.html +++ b/js-stellar-base_src_memo.js.html @@ -24,7 +24,7 @@
@@ -296,7 +296,7 @@

js-stellar-base/src/memo.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_muxed_account.js.html b/js-stellar-base_src_muxed_account.js.html index c1117879..ce2ae28a 100644 --- a/js-stellar-base_src_muxed_account.js.html +++ b/js-stellar-base_src_muxed_account.js.html @@ -24,7 +24,7 @@
@@ -188,7 +188,7 @@

js-stellar-base/src/muxed_account.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_network.js.html b/js-stellar-base_src_network.js.html index 6e313f35..4eb5c295 100644 --- a/js-stellar-base_src_network.js.html +++ b/js-stellar-base_src_network.js.html @@ -24,7 +24,7 @@
@@ -67,7 +67,7 @@

js-stellar-base/src/network.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_numbers_index.js.html b/js-stellar-base_src_numbers_index.js.html index 98e1d458..6eddf918 100644 --- a/js-stellar-base_src_numbers_index.js.html +++ b/js-stellar-base_src_numbers_index.js.html @@ -24,7 +24,7 @@
@@ -110,7 +110,7 @@

js-stellar-base/src/numbers/index.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_numbers_int128.js.html b/js-stellar-base_src_numbers_int128.js.html index 3ca81f78..58dfac33 100644 --- a/js-stellar-base_src_numbers_int128.js.html +++ b/js-stellar-base_src_numbers_int128.js.html @@ -24,7 +24,7 @@
@@ -74,7 +74,7 @@

js-stellar-base/src/numbers/int128.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_numbers_int256.js.html b/js-stellar-base_src_numbers_int256.js.html index c792aa90..9f653efe 100644 --- a/js-stellar-base_src_numbers_int256.js.html +++ b/js-stellar-base_src_numbers_int256.js.html @@ -24,7 +24,7 @@
@@ -74,7 +74,7 @@

js-stellar-base/src/numbers/int256.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_numbers_sc_int.js.html b/js-stellar-base_src_numbers_sc_int.js.html index b5fd5d74..a1e2d3eb 100644 --- a/js-stellar-base_src_numbers_sc_int.js.html +++ b/js-stellar-base_src_numbers_sc_int.js.html @@ -24,7 +24,7 @@
@@ -165,7 +165,7 @@

js-stellar-base/src/numbers/sc_int.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_numbers_uint128.js.html b/js-stellar-base_src_numbers_uint128.js.html index fe36e094..06874db5 100644 --- a/js-stellar-base_src_numbers_uint128.js.html +++ b/js-stellar-base_src_numbers_uint128.js.html @@ -24,7 +24,7 @@
@@ -74,7 +74,7 @@

js-stellar-base/src/numbers/uint128.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_numbers_uint256.js.html b/js-stellar-base_src_numbers_uint256.js.html index 5485ce0c..7b161162 100644 --- a/js-stellar-base_src_numbers_uint256.js.html +++ b/js-stellar-base_src_numbers_uint256.js.html @@ -24,7 +24,7 @@
@@ -74,7 +74,7 @@

js-stellar-base/src/numbers/uint256.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_numbers_xdr_large_int.js.html b/js-stellar-base_src_numbers_xdr_large_int.js.html index 40aa4d8f..fbd382c0 100644 --- a/js-stellar-base_src_numbers_xdr_large_int.js.html +++ b/js-stellar-base_src_numbers_xdr_large_int.js.html @@ -24,7 +24,7 @@
@@ -305,7 +305,7 @@

js-stellar-base/src/numbers/xdr_large_int.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operation.js.html b/js-stellar-base_src_operation.js.html index da571f28..c9aa536f 100644 --- a/js-stellar-base_src_operation.js.html +++ b/js-stellar-base_src_operation.js.html @@ -24,7 +24,7 @@
@@ -727,7 +727,7 @@

js-stellar-base/src/operation.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_account_merge.js.html b/js-stellar-base_src_operations_account_merge.js.html index bce70905..00c26da3 100644 --- a/js-stellar-base_src_operations_account_merge.js.html +++ b/js-stellar-base_src_operations_account_merge.js.html @@ -24,7 +24,7 @@
@@ -80,7 +80,7 @@

js-stellar-base/src/operations/account_merge.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_allow_trust.js.html b/js-stellar-base_src_operations_allow_trust.js.html index 0543743e..46dd0d82 100644 --- a/js-stellar-base_src_operations_allow_trust.js.html +++ b/js-stellar-base_src_operations_allow_trust.js.html @@ -24,7 +24,7 @@
@@ -106,7 +106,7 @@

js-stellar-base/src/operations/allow_trust.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_begin_sponsoring_future_reserves.js.html b/js-stellar-base_src_operations_begin_sponsoring_future_reserves.js.html index b460e161..32da049d 100644 --- a/js-stellar-base_src_operations_begin_sponsoring_future_reserves.js.html +++ b/js-stellar-base_src_operations_begin_sponsoring_future_reserves.js.html @@ -24,7 +24,7 @@
@@ -84,7 +84,7 @@

js-stellar-base/src/operations/begin_sponsoring_future_re
- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_bump_footprint_expiration.js.html b/js-stellar-base_src_operations_bump_footprint_expiration.js.html index 4ed9debf..bcd9181e 100644 --- a/js-stellar-base_src_operations_bump_footprint_expiration.js.html +++ b/js-stellar-base_src_operations_bump_footprint_expiration.js.html @@ -24,7 +24,7 @@
@@ -92,7 +92,7 @@

js-stellar-base/src/operations/bump_footprint_expiration.
- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_bump_sequence.js.html b/js-stellar-base_src_operations_bump_sequence.js.html index d6d786f0..be38bfe1 100644 --- a/js-stellar-base_src_operations_bump_sequence.js.html +++ b/js-stellar-base_src_operations_bump_sequence.js.html @@ -24,7 +24,7 @@
@@ -88,7 +88,7 @@

js-stellar-base/src/operations/bump_sequence.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_change_trust.js.html b/js-stellar-base_src_operations_change_trust.js.html index 521c747f..e6f7d463 100644 --- a/js-stellar-base_src_operations_change_trust.js.html +++ b/js-stellar-base_src_operations_change_trust.js.html @@ -24,7 +24,7 @@
@@ -103,7 +103,7 @@

js-stellar-base/src/operations/change_trust.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_claim_claimable_balance.js.html b/js-stellar-base_src_operations_claim_claimable_balance.js.html index 60c7f2ed..a9f74320 100644 --- a/js-stellar-base_src_operations_claim_claimable_balance.js.html +++ b/js-stellar-base_src_operations_claim_claimable_balance.js.html @@ -24,7 +24,7 @@
@@ -92,7 +92,7 @@

js-stellar-base/src/operations/claim_claimable_balance.js
- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_clawback.js.html b/js-stellar-base_src_operations_clawback.js.html index 64ccf842..046312ad 100644 --- a/js-stellar-base_src_operations_clawback.js.html +++ b/js-stellar-base_src_operations_clawback.js.html @@ -24,7 +24,7 @@
@@ -93,7 +93,7 @@

js-stellar-base/src/operations/clawback.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_clawback_claimable_balance.js.html b/js-stellar-base_src_operations_clawback_claimable_balance.js.html index 159c706b..79e3a480 100644 --- a/js-stellar-base_src_operations_clawback_claimable_balance.js.html +++ b/js-stellar-base_src_operations_clawback_claimable_balance.js.html @@ -24,7 +24,7 @@
@@ -88,7 +88,7 @@

js-stellar-base/src/operations/clawback_claimable_balance
- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_create_account.js.html b/js-stellar-base_src_operations_create_account.js.html index 68ca7b07..cd047d21 100644 --- a/js-stellar-base_src_operations_create_account.js.html +++ b/js-stellar-base_src_operations_create_account.js.html @@ -24,7 +24,7 @@
@@ -88,7 +88,7 @@

js-stellar-base/src/operations/create_account.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_create_claimable_balance.js.html b/js-stellar-base_src_operations_create_claimable_balance.js.html index 851c5b16..3344de41 100644 --- a/js-stellar-base_src_operations_create_claimable_balance.js.html +++ b/js-stellar-base_src_operations_create_claimable_balance.js.html @@ -24,7 +24,7 @@
@@ -120,7 +120,7 @@

js-stellar-base/src/operations/create_claimable_balance.j
- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_create_passive_sell_offer.js.html b/js-stellar-base_src_operations_create_passive_sell_offer.js.html index bb0dd95b..082df176 100644 --- a/js-stellar-base_src_operations_create_passive_sell_offer.js.html +++ b/js-stellar-base_src_operations_create_passive_sell_offer.js.html @@ -24,7 +24,7 @@
@@ -93,7 +93,7 @@

js-stellar-base/src/operations/create_passive_sell_offer.
- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_end_sponsoring_future_reserves.js.html b/js-stellar-base_src_operations_end_sponsoring_future_reserves.js.html index f2a626f6..061a0260 100644 --- a/js-stellar-base_src_operations_end_sponsoring_future_reserves.js.html +++ b/js-stellar-base_src_operations_end_sponsoring_future_reserves.js.html @@ -24,7 +24,7 @@
@@ -72,7 +72,7 @@

js-stellar-base/src/operations/end_sponsoring_future_rese
- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_inflation.js.html b/js-stellar-base_src_operations_inflation.js.html index 64e65d53..e17b9cfc 100644 --- a/js-stellar-base_src_operations_inflation.js.html +++ b/js-stellar-base_src_operations_inflation.js.html @@ -24,7 +24,7 @@
@@ -67,7 +67,7 @@

js-stellar-base/src/operations/inflation.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_invoke_host_function.js.html b/js-stellar-base_src_operations_invoke_host_function.js.html index 74df8d4c..e1d49132 100644 --- a/js-stellar-base_src_operations_invoke_host_function.js.html +++ b/js-stellar-base_src_operations_invoke_host_function.js.html @@ -24,7 +24,7 @@
@@ -88,7 +88,7 @@

js-stellar-base/src/operations/invoke_host_function.js
- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_liquidity_pool_deposit.js.html b/js-stellar-base_src_operations_liquidity_pool_deposit.js.html index a299ad5e..39267905 100644 --- a/js-stellar-base_src_operations_liquidity_pool_deposit.js.html +++ b/js-stellar-base_src_operations_liquidity_pool_deposit.js.html @@ -24,7 +24,7 @@
@@ -111,7 +111,7 @@

js-stellar-base/src/operations/liquidity_pool_deposit.js<
- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_liquidity_pool_withdraw.js.html b/js-stellar-base_src_operations_liquidity_pool_withdraw.js.html index 5b9324ca..f69c9493 100644 --- a/js-stellar-base_src_operations_liquidity_pool_withdraw.js.html +++ b/js-stellar-base_src_operations_liquidity_pool_withdraw.js.html @@ -24,7 +24,7 @@
@@ -99,7 +99,7 @@

js-stellar-base/src/operations/liquidity_pool_withdraw.js
- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_manage_buy_offer.js.html b/js-stellar-base_src_operations_manage_buy_offer.js.html index 1d677219..9d63cd3e 100644 --- a/js-stellar-base_src_operations_manage_buy_offer.js.html +++ b/js-stellar-base_src_operations_manage_buy_offer.js.html @@ -24,7 +24,7 @@
@@ -98,7 +98,7 @@

js-stellar-base/src/operations/manage_buy_offer.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_manage_data.js.html b/js-stellar-base_src_operations_manage_data.js.html index b22388b0..405ec4d5 100644 --- a/js-stellar-base_src_operations_manage_data.js.html +++ b/js-stellar-base_src_operations_manage_data.js.html @@ -24,7 +24,7 @@
@@ -97,7 +97,7 @@

js-stellar-base/src/operations/manage_data.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_manage_sell_offer.js.html b/js-stellar-base_src_operations_manage_sell_offer.js.html index 41e5bbf5..4c5286f9 100644 --- a/js-stellar-base_src_operations_manage_sell_offer.js.html +++ b/js-stellar-base_src_operations_manage_sell_offer.js.html @@ -24,7 +24,7 @@
@@ -98,7 +98,7 @@

js-stellar-base/src/operations/manage_sell_offer.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_path_payment_strict_receive.js.html b/js-stellar-base_src_operations_path_payment_strict_receive.js.html index 877e4b3a..f0524025 100644 --- a/js-stellar-base_src_operations_path_payment_strict_receive.js.html +++ b/js-stellar-base_src_operations_path_payment_strict_receive.js.html @@ -24,7 +24,7 @@
@@ -117,7 +117,7 @@

js-stellar-base/src/operations/path_payment_strict_receiv
- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_path_payment_strict_send.js.html b/js-stellar-base_src_operations_path_payment_strict_send.js.html index cf1c46a8..870a99b3 100644 --- a/js-stellar-base_src_operations_path_payment_strict_send.js.html +++ b/js-stellar-base_src_operations_path_payment_strict_send.js.html @@ -24,7 +24,7 @@
@@ -116,7 +116,7 @@

js-stellar-base/src/operations/path_payment_strict_send.j
- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_payment.js.html b/js-stellar-base_src_operations_payment.js.html index 8637d924..fff4e706 100644 --- a/js-stellar-base_src_operations_payment.js.html +++ b/js-stellar-base_src_operations_payment.js.html @@ -24,7 +24,7 @@
@@ -96,7 +96,7 @@

js-stellar-base/src/operations/payment.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_restore_footprint.js.html b/js-stellar-base_src_operations_restore_footprint.js.html index 2ec5b4cf..b08bf33d 100644 --- a/js-stellar-base_src_operations_restore_footprint.js.html +++ b/js-stellar-base_src_operations_restore_footprint.js.html @@ -24,7 +24,7 @@
@@ -80,7 +80,7 @@

js-stellar-base/src/operations/restore_footprint.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_revoke_sponsorship.js.html b/js-stellar-base_src_operations_revoke_sponsorship.js.html index cbb318e1..7a18fd23 100644 --- a/js-stellar-base_src_operations_revoke_sponsorship.js.html +++ b/js-stellar-base_src_operations_revoke_sponsorship.js.html @@ -24,7 +24,7 @@
@@ -367,7 +367,7 @@

js-stellar-base/src/operations/revoke_sponsorship.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_set_options.js.html b/js-stellar-base_src_operations_set_options.js.html index 4fce81ed..68099c3f 100644 --- a/js-stellar-base_src_operations_set_options.js.html +++ b/js-stellar-base_src_operations_set_options.js.html @@ -24,7 +24,7 @@
@@ -235,7 +235,7 @@

js-stellar-base/src/operations/set_options.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_operations_set_trustline_flags.js.html b/js-stellar-base_src_operations_set_trustline_flags.js.html index a82ac08b..7bd938a6 100644 --- a/js-stellar-base_src_operations_set_trustline_flags.js.html +++ b/js-stellar-base_src_operations_set_trustline_flags.js.html @@ -24,7 +24,7 @@
@@ -137,7 +137,7 @@

js-stellar-base/src/operations/set_trustline_flags.js

- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_scval.js.html b/js-stellar-base_src_scval.js.html index b40825bb..3a94944c 100644 --- a/js-stellar-base_src_scval.js.html +++ b/js-stellar-base_src_scval.js.html @@ -24,7 +24,7 @@
@@ -421,7 +421,7 @@

js-stellar-base/src/scval.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_signerkey.js.html b/js-stellar-base_src_signerkey.js.html index 43b28177..a243fa2c 100644 --- a/js-stellar-base_src_signerkey.js.html +++ b/js-stellar-base_src_signerkey.js.html @@ -24,7 +24,7 @@
@@ -143,7 +143,7 @@

js-stellar-base/src/signerkey.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_signing.js.html b/js-stellar-base_src_signing.js.html index 26017bde..11fedab1 100644 --- a/js-stellar-base_src_signing.js.html +++ b/js-stellar-base_src_signing.js.html @@ -24,7 +24,7 @@
@@ -158,7 +158,7 @@

js-stellar-base/src/signing.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_soroban.js.html b/js-stellar-base_src_soroban.js.html index e281ac17..6d8ee6be 100644 --- a/js-stellar-base_src_soroban.js.html +++ b/js-stellar-base_src_soroban.js.html @@ -24,7 +24,7 @@
@@ -40,27 +40,31 @@

js-stellar-base/src/soroban.js

/**
- * Soroban helper class
- * formatting, parsing, and etc
  * @class Soroban
+ * Soroban helper class to assist with formatting and parsing token amounts.
  */
 export class Soroban {
   /**
-   * All arithmetic inside the contract is performed on integers to
-   * avoid potential precision and consistency issues of floating-point
+   * Given a whole number smart contract amount of a token and an amount of
+   * decimal places (if the token has any), it returns a "display" value.
    *
-   * This function takes the smart contract value and its decimals (if the token has any) and returns a display value
-   * @param {string} amount - the token amount you want to display
-   * @param {number} decimals - specify how many decimal places a token has
-   * @returns {string} - display value
+   * All arithmetic inside the contract is performed on integers to avoid
+   * potential precision and consistency issues of floating-point.
+   *
+   * @param {string} amount   the token amount you want to display
+   * @param {number} decimals specify how many decimal places a token has
+   *
+   * @returns {string} the display value
+   * @throws {TypeError} if the given amount has a decimal point already
+   * @example
+   * formatTokenAmount("123000", 4) === "12.3";
    */
   static formatTokenAmount(amount, decimals) {
-    let formatted = amount;
-
     if (amount.includes('.')) {
-      throw new Error('No decimal is allowed');
+      throw new TypeError('No decimals are allowed');
     }
 
+    let formatted = amount;
     if (decimals > 0) {
       if (decimals > formatted.length) {
         formatted = ['0', formatted.toString().padStart(decimals, '0')].join(
@@ -79,19 +83,24 @@ 

js-stellar-base/src/soroban.js

} /** - * parse token amount to use it on smart contract + * Parse a token amount to use it on smart contract * * This function takes the display value and its decimals (if the token has * any) and returns a string that'll be used within the smart contract. - * @param {string} value - the token amount you want to use it on smart contract - * @param {number} decimals - specify how many decimal places a token has - * @returns {string} - smart contract value * + * @param {string} value the token amount you want to use it on smart + * contract which you've been displaying in a UI + * @param {number} decimals the number of decimal places expected in the + * display value (different than the "actual" number, because suffix zeroes + * might not be present) + * + * @returns {string} the whole number token amount represented by the display + * value with the decimal places shifted over * * @example * const displayValueAmount = "123.4560" - * const parsedAmountForSmartContract = parseTokenAmount("123.4560", 5); - * parsedAmountForSmartContract === "12345600" + * const parsedAmtForSmartContract = parseTokenAmount(displayValueAmount, 5); + * parsedAmtForSmartContract === "12345600" */ static parseTokenAmount(value, decimals) { const [whole, fraction, ...rest] = value.split('.').slice(); @@ -119,7 +128,7 @@

js-stellar-base/src/soroban.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_sorobandata_builder.js.html b/js-stellar-base_src_sorobandata_builder.js.html index c905b6c7..7bfd55aa 100644 --- a/js-stellar-base_src_sorobandata_builder.js.html +++ b/js-stellar-base_src_sorobandata_builder.js.html @@ -24,7 +24,7 @@
@@ -248,7 +248,7 @@

js-stellar-base/src/sorobandata_builder.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_strkey.js.html b/js-stellar-base_src_strkey.js.html index 2ce4ab83..55ed374d 100644 --- a/js-stellar-base_src_strkey.js.html +++ b/js-stellar-base_src_strkey.js.html @@ -24,7 +24,7 @@
@@ -449,7 +449,7 @@

js-stellar-base/src/strkey.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_transaction.js.html b/js-stellar-base_src_transaction.js.html index be39269c..aaf0ae1d 100644 --- a/js-stellar-base_src_transaction.js.html +++ b/js-stellar-base_src_transaction.js.html @@ -24,7 +24,7 @@
@@ -419,7 +419,7 @@

js-stellar-base/src/transaction.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_transaction_base.js.html b/js-stellar-base_src_transaction_base.js.html index a5285f90..5d65fe43 100644 --- a/js-stellar-base_src_transaction_base.js.html +++ b/js-stellar-base_src_transaction_base.js.html @@ -24,7 +24,7 @@
@@ -268,7 +268,7 @@

js-stellar-base/src/transaction_base.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_transaction_builder.js.html b/js-stellar-base_src_transaction_builder.js.html index 758ac581..f7e5938e 100644 --- a/js-stellar-base_src_transaction_builder.js.html +++ b/js-stellar-base_src_transaction_builder.js.html @@ -24,7 +24,7 @@
@@ -222,7 +222,7 @@

js-stellar-base/src/transaction_builder.js

throw new TypeError(`expected a 'Transaction', got: ${tx}`); } - const sequenceNum = `${parseInt(tx.sequence, 10) - 1}`; + const sequenceNum = (BigInt(tx.sequence) - 1n).toString(); let source; // rebuild the source account based on the strkey @@ -851,7 +851,7 @@

js-stellar-base/src/transaction_builder.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/js-stellar-base_src_util_decode_encode_muxed_account.js.html b/js-stellar-base_src_util_decode_encode_muxed_account.js.html index 9b3307fd..1e21f9fb 100644 --- a/js-stellar-base_src_util_decode_encode_muxed_account.js.html +++ b/js-stellar-base_src_util_decode_encode_muxed_account.js.html @@ -24,7 +24,7 @@
@@ -175,7 +175,7 @@

js-stellar-base/src/util/decode_encode_muxed_account.js
- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/lib_contract_spec.js.html b/lib_contract_spec.js.html index cbaddcc4..37ece897 100644 --- a/lib_contract_spec.js.html +++ b/lib_contract_spec.js.html @@ -24,7 +24,7 @@
@@ -81,11 +81,11 @@

lib/contract_spec.js

*/ constructor(entries) { if (entries.length == 0) { - throw new Error("Contract spec must have at least one entry"); + throw new Error('Contract spec must have at least one entry'); } let entry = entries[0]; - if (typeof entry === "string") { - this.entries = entries.map(s => _stellarBase.xdr.ScSpecEntry.fromXDR(s, "base64")); + if (typeof entry === 'string') { + this.entries = entries.map(s => _stellarBase.xdr.ScSpecEntry.fromXDR(s, 'base64')); } else { this.entries = entries; } @@ -116,13 +116,11 @@

lib/contract_spec.js

* @throws {Error} if argument is missing or incorrect type * * @example - * ```js * const args = { * arg1: 'value1', * arg2: 1234 * }; * const scArgs = contractSpec.funcArgsToScVals('funcName', args); - * ``` */ funcArgsToScVals(name, args) { let fn = this.getFunc(name); @@ -139,13 +137,11 @@

lib/contract_spec.js

* @throws {Error} if return type mismatch or invalid input * * @example - * ```js * const resultScv = 'AAA=='; // Base64 encoded ScVal * const result = contractSpec.funcResToNative('funcName', resultScv); - * ``` */ funcResToNative(name, val_or_base64) { - let val = typeof val_or_base64 === "string" ? _stellarBase.xdr.ScVal.fromXDR(val_or_base64, "base64") : val_or_base64; + let val = typeof val_or_base64 === 'string' ? _stellarBase.xdr.ScVal.fromXDR(val_or_base64, 'base64') : val_or_base64; let func = this.getFunc(name); let outputs = func.outputs(); if (outputs.length === 0) { @@ -205,7 +201,7 @@

lib/contract_spec.js

return this.nativeToScVal(val, opt.valueType()); } switch (typeof val) { - case "object": + case 'object': { var _val$constructor; if (val === null) { @@ -288,14 +284,14 @@

lib/contract_spec.js

} return _stellarBase.xdr.ScVal.scvMap(entries); } - if ((((_val$constructor = val.constructor) === null || _val$constructor === void 0 ? void 0 : _val$constructor.name) ?? "") !== "Object") { + if ((((_val$constructor = val.constructor) === null || _val$constructor === void 0 ? void 0 : _val$constructor.name) ?? '') !== 'Object') { var _val$constructor2; throw new TypeError(`cannot interpret ${(_val$constructor2 = val.constructor) === null || _val$constructor2 === void 0 ? void 0 : _val$constructor2.name} value as ScVal (${JSON.stringify(val)})`); } throw new TypeError(`Received object ${val} did not match the provided type ${ty}`); } - case "number": - case "bigint": + case 'number': + case 'bigint': { switch (value) { case _stellarBase.xdr.ScSpecType.scSpecTypeU32().value: @@ -316,16 +312,16 @@

lib/contract_spec.js

throw new TypeError(`invalid type (${ty}) specified for integer`); } } - case "string": + case 'string': return stringToScVal(val, t); - case "boolean": + case 'boolean': { if (value !== _stellarBase.xdr.ScSpecType.scSpecTypeBool().value) { throw TypeError(`Type ${ty} was not bool, but value was bool`); } return _stellarBase.xdr.ScVal.scvBool(val); } - case "undefined": + case 'undefined': { if (!ty) { return _stellarBase.xdr.ScVal.scvVoid(); @@ -338,7 +334,7 @@

lib/contract_spec.js

throw new TypeError(`Type ${ty} was not void, but value was undefined`); } } - case "function": + case 'function': // FIXME: Is this too helpful? return this.nativeToScVal(val(), ty); default: @@ -349,7 +345,7 @@

lib/contract_spec.js

let entry = this.findEntry(name); switch (entry.switch()) { case _stellarBase.xdr.ScSpecEntryKind.scSpecEntryUdtEnumV0(): - if (typeof val !== "number") { + if (typeof val !== 'number') { throw new TypeError(`expected number for enum ${name}, but got ${typeof val}`); } return this.nativeToEnum(val, entry.value()); @@ -406,7 +402,7 @@

lib/contract_spec.js

let fields = struct.fields(); if (fields.some(isNumeric)) { if (!fields.every(isNumeric)) { - throw new Error("mixed numeric and non-numeric field names are not allowed"); + throw new Error('mixed numeric and non-numeric field names are not allowed'); } return _stellarBase.xdr.ScVal.scvVec(fields.map((_, i) => this.nativeToScVal(val[i], fields[i].type()))); } @@ -435,7 +431,7 @@

lib/contract_spec.js

* @throws {Error} if ScVal cannot be converted to the given type */ scValStrToNative(scv, typeDef) { - return this.scValToNative(_stellarBase.xdr.ScVal.fromXDR(scv, "base64"), typeDef); + return this.scValToNative(_stellarBase.xdr.ScVal.fromXDR(scv, 'base64'), typeDef); } /** @@ -653,7 +649,7 @@

lib/contract_spec.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/lib_jsonrpc.js.html b/lib_jsonrpc.js.html index 2eceb4c0..7c291048 100644 --- a/lib_jsonrpc.js.html +++ b/lib_jsonrpc.js.html @@ -24,7 +24,7 @@
@@ -56,13 +56,13 @@

lib/jsonrpc.js

params = null; } const response = await _axios.default.post(url, { - jsonrpc: "2.0", + jsonrpc: '2.0', // TODO: Generate a unique request id id: 1, method, params }); - if (hasOwnProperty(response.data, "error")) { + if (hasOwnProperty(response.data, 'error')) { throw response.data.error; } else { var _response$data; @@ -75,13 +75,13 @@

lib/jsonrpc.js

*/ async function postObject(url, method, param) { const response = await _axios.default.post(url, { - jsonrpc: "2.0", + jsonrpc: '2.0', // TODO: Generate a unique request id id: 1, method, params: param }); - if (hasOwnProperty(response.data, "error")) { + if (hasOwnProperty(response.data, 'error')) { throw response.data.error; } else { var _response$data2; @@ -105,7 +105,7 @@

lib/jsonrpc.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/lib_parsers.js.html b/lib_parsers.js.html new file mode 100644 index 00000000..e8172175 --- /dev/null +++ b/lib_parsers.js.html @@ -0,0 +1,184 @@ + + + + + + lib/parsers.js - Documentation + + + + + + + + + + + + + + + + + +
+ +

lib/parsers.js

+ + + + + + + +
+
+
"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+  value: true
+});
+exports.parseRawEvents = parseRawEvents;
+exports.parseRawLedgerEntries = parseRawLedgerEntries;
+exports.parseRawSendTransaction = parseRawSendTransaction;
+exports.parseRawSimulation = parseRawSimulation;
+var _stellarBase = require("stellar-base");
+var _soroban_rpc = require("./soroban_rpc");
+function parseRawSendTransaction(r) {
+  const errResult = r.errorResultXdr;
+  delete r.errorResultXdr;
+  if (!!errResult) {
+    return {
+      ...r,
+      errorResult: _stellarBase.xdr.TransactionResult.fromXDR(errResult, 'base64')
+    };
+  }
+  return {
+    ...r
+  };
+}
+function parseRawEvents(r) {
+  return {
+    latestLedger: r.latestLedger,
+    events: (r.events ?? []).map(evt => {
+      return {
+        ...evt,
+        contractId: new _stellarBase.Contract(evt.contractId),
+        topic: evt.topic.map(topic => _stellarBase.xdr.ScVal.fromXDR(topic, 'base64')),
+        value: _stellarBase.xdr.DiagnosticEvent.fromXDR(evt.value.xdr, 'base64')
+      };
+    })
+  };
+}
+function parseRawLedgerEntries(raw) {
+  return {
+    latestLedger: raw.latestLedger,
+    entries: (raw.entries ?? []).map(rawEntry => {
+      if (!rawEntry.key || !rawEntry.xdr) {
+        throw new TypeError(`invalid ledger entry: ${JSON.stringify(rawEntry)}`);
+      }
+      return {
+        lastModifiedLedgerSeq: rawEntry.lastModifiedLedgerSeq,
+        key: _stellarBase.xdr.LedgerKey.fromXDR(rawEntry.key, 'base64'),
+        val: _stellarBase.xdr.LedgerEntryData.fromXDR(rawEntry.xdr, 'base64'),
+        expirationLedgerSeq: rawEntry.expirationLedgerSeq
+      };
+    })
+  };
+}
+
+/**
+ * Converts a raw response schema into one with parsed XDR fields and a
+ * simplified interface.
+ *
+ * @param raw   the raw response schema (parsed ones are allowed, best-effort
+ *    detected, and returned untouched)
+ *
+ * @returns the original parameter (if already parsed), parsed otherwise
+ *
+ * @warning This API is only exported for testing purposes and should not be
+ *          relied on or considered "stable".
+ */
+function parseRawSimulation(sim) {
+  var _sim$events;
+  const looksRaw = _soroban_rpc.SorobanRpc.isSimulationRaw(sim);
+  if (!looksRaw) {
+    // Gordon Ramsey in shambles
+    return sim;
+  }
+
+  // shared across all responses
+  let base = {
+    _parsed: true,
+    id: sim.id,
+    latestLedger: sim.latestLedger,
+    events: ((_sim$events = sim.events) === null || _sim$events === void 0 ? void 0 : _sim$events.map(evt => _stellarBase.xdr.DiagnosticEvent.fromXDR(evt, 'base64'))) ?? []
+  };
+
+  // error type: just has error string
+  if (typeof sim.error === 'string') {
+    return {
+      ...base,
+      error: sim.error
+    };
+  }
+  return parseSuccessful(sim, base);
+}
+function parseSuccessful(sim, partial) {
+  var _sim$results;
+  // success type: might have a result (if invoking) and...
+  const success = {
+    ...partial,
+    transactionData: new _stellarBase.SorobanDataBuilder(sim.transactionData),
+    minResourceFee: sim.minResourceFee,
+    cost: sim.cost,
+    ...(
+    // coalesce 0-or-1-element results[] list into a single result struct
+    // with decoded fields if present
+    (((_sim$results = sim.results) === null || _sim$results === void 0 ? void 0 : _sim$results.length) ?? 0 > 0) && {
+      result: sim.results.map(row => {
+        return {
+          auth: (row.auth ?? []).map(entry => _stellarBase.xdr.SorobanAuthorizationEntry.fromXDR(entry, 'base64')),
+          // if return value is missing ("falsy") we coalesce to void
+          retval: !!row.xdr ? _stellarBase.xdr.ScVal.fromXDR(row.xdr, 'base64') : _stellarBase.xdr.ScVal.scvVoid()
+        };
+      })[0]
+    })
+  };
+  if (!sim.restorePreamble || sim.restorePreamble.transactionData === '') {
+    return success;
+  }
+
+  // ...might have a restoration hint (if some state is expired)
+  return {
+    ...success,
+    restorePreamble: {
+      minResourceFee: sim.restorePreamble.minResourceFee,
+      transactionData: new _stellarBase.SorobanDataBuilder(sim.restorePreamble.transactionData)
+    }
+  };
+}
+
+
+ + + + +
+ +
+ +
+ Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme. +
+ + + + + diff --git a/lib_server.js.html b/lib_server.js.html index e9981c0a..3e975e0d 100644 --- a/lib_server.js.html +++ b/lib_server.js.html @@ -24,7 +24,7 @@
@@ -51,23 +51,22 @@

lib/server.js

var jsonrpc = _interopRequireWildcard(require("./jsonrpc")); var _soroban_rpc = require("./soroban_rpc"); var _transaction = require("./transaction"); -function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } -function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } +var _parsers = require("./parsers"); +function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } +function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /* tslint:disable:variable-name no-namespace */ -const SUBMIT_TRANSACTION_TIMEOUT = 60 * 1000; +const SUBMIT_TRANSACTION_TIMEOUT = exports.SUBMIT_TRANSACTION_TIMEOUT = 60 * 1000; /** * Specifies the durability namespace of contract-related ledger entries. */ -exports.SUBMIT_TRANSACTION_TIMEOUT = SUBMIT_TRANSACTION_TIMEOUT; -let Durability = /*#__PURE__*/function (Durability) { +let Durability = exports.Durability = /*#__PURE__*/function (Durability) { Durability["Temporary"] = "temporary"; Durability["Persistent"] = "persistent"; return Durability; }({}); -exports.Durability = Durability; /** * Handles the network connection to a Soroban RPC instance, exposing an * interface for requests to that instance. @@ -96,7 +95,7 @@

lib/server.js

return config; }); } - if (this.serverURL.protocol() !== "https" && !opts.allowHttp) { + if (this.serverURL.protocol() !== 'https' && !opts.allowHttp) { throw new Error("Cannot connect to insecure Soroban RPC server if `allowHttp` isn't set"); } } @@ -121,18 +120,16 @@

lib/server.js

*/ async getAccount(address) { const ledgerKey = _stellarBase.xdr.LedgerKey.account(new _stellarBase.xdr.LedgerKeyAccount({ - accountId: _stellarBase.xdr.PublicKey.publicKeyTypeEd25519(_stellarBase.StrKey.decodeEd25519PublicKey(address)) + accountId: _stellarBase.Keypair.fromPublicKey(address).xdrPublicKey() })); const resp = await this.getLedgerEntries(ledgerKey); - const entries = resp.entries ?? []; - if (entries.length === 0) { + if (resp.entries.length === 0) { return Promise.reject({ code: 404, message: `Account not found: ${address}` }); } - const ledgerEntryData = entries[0].xdr; - const accountEntry = _stellarBase.xdr.LedgerEntryData.fromXDR(ledgerEntryData, "base64").account(); + const accountEntry = resp.entries[0].val.account(); return new _stellarBase.Account(address, accountEntry.seqNum().toString()); } @@ -150,7 +147,7 @@

lib/server.js

* }); */ async getHealth() { - return jsonrpc.post(this.serverURL.toString(), "getHealth"); + return jsonrpc.post(this.serverURL.toString(), 'getHealth'); } /** @@ -177,8 +174,9 @@

lib/server.js

* @example * const contractId = "CCJZ5DGASBWQXR5MPFCJXMBI333XE5U3FSJTNQU7RIKE3P5GN2K2WYD5"; * const key = xdr.ScVal.scvSymbol("counter"); - * server.getContractData(contractId, key, 'temporary').then(data => { - * console.log("value:", data.xdr); + * server.getContractData(contractId, key, Durability.Temporary).then(data => { + * console.log("value:", data.val); + * console.log("expirationLedgerSeq:", data.expirationLedgerSeq); * console.log("lastModified:", data.lastModifiedLedgerSeq); * console.log("latestLedger:", data.latestLedger); * }); @@ -186,7 +184,7 @@

lib/server.js

async getContractData(contract, key, durability = Durability.Persistent) { // coalesce `contract` param variants to an ScAddress let scAddress; - if (typeof contract === "string") { + if (typeof contract === 'string') { scAddress = new _stellarBase.Contract(contract).address().toScAddress(); } else if (contract instanceof _stellarBase.Address) { scAddress = contract.toScAddress(); @@ -211,15 +209,14 @@

lib/server.js

contract: scAddress, durability: xdrDurability })); - return this.getLedgerEntries(contractKey).then(response => { - const entries = response.entries ?? []; - if (entries.length === 0) { + return this.getLedgerEntries(contractKey).then(r => { + if (r.entries.length === 0) { return Promise.reject({ code: 404, - message: `Contract data not found. Contract: ${_stellarBase.Address.fromScAddress(scAddress).toString()}, Key: ${key.toXDR("base64")}, Durability: ${durability}` + message: `Contract data not found. Contract: ${_stellarBase.Address.fromScAddress(scAddress).toString()}, Key: ${key.toXDR('base64')}, Durability: ${durability}` }); } - return entries[0]; + return r.entries[0]; }); } @@ -238,6 +235,7 @@

lib/server.js

* @returns {Promise<SorobanRpc.GetLedgerEntriesResponse>} the current * on-chain values for the given ledger keys * + * @see Server._getLedgerEntries * @see https://soroban.stellar.org/api/methods/getLedgerEntries * @example * const contractId = "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM"; @@ -249,13 +247,17 @@

lib/server.js

* server.getLedgerEntries([key]).then(response => { * const ledgerData = response.entries[0]; * console.log("key:", ledgerData.key); - * console.log("value:", ledgerData.xdr); + * console.log("value:", ledgerData.val); + * console.log("expirationLedgerSeq:", ledgerData.expirationLedgerSeq); * console.log("lastModified:", ledgerData.lastModifiedLedgerSeq); * console.log("latestLedger:", response.latestLedger); * }); */ async getLedgerEntries(...keys) { - return await jsonrpc.post(this.serverURL.toString(), "getLedgerEntries", keys.map(k => k.toXDR("base64"))); + return this._getLedgerEntries(...keys).then(_parsers.parseRawLedgerEntries); + } + async _getLedgerEntries(...keys) { + return jsonrpc.post(this.serverURL.toString(), 'getLedgerEntries', expandRequestIncludeExpirationLedgers(keys).map(k => k.toXDR('base64'))).then(response => mergeResponseExpirationLedgers(response, keys)); } /** @@ -280,33 +282,37 @@

lib/server.js

* }); */ async getTransaction(hash) { - const raw = await jsonrpc.post(this.serverURL.toString(), "getTransaction", hash); - let successInfo = {}; - if (raw.status === _soroban_rpc.SorobanRpc.GetTransactionStatus.SUCCESS) { - var _meta$v3$sorobanMeta; - const meta = _stellarBase.xdr.TransactionMeta.fromXDR(raw.resultMetaXdr, "base64"); - successInfo = { - ledger: raw.ledger, - createdAt: raw.createdAt, - applicationOrder: raw.applicationOrder, - feeBump: raw.feeBump, - envelopeXdr: _stellarBase.xdr.TransactionEnvelope.fromXDR(raw.envelopeXdr, "base64"), - resultXdr: _stellarBase.xdr.TransactionResult.fromXDR(raw.resultXdr, "base64"), - resultMetaXdr: meta, - ...(meta.switch() === 3 && meta.v3().sorobanMeta() !== null && { - returnValue: (_meta$v3$sorobanMeta = meta.v3().sorobanMeta()) === null || _meta$v3$sorobanMeta === void 0 ? void 0 : _meta$v3$sorobanMeta.returnValue() - }) + return this._getTransaction(hash).then(raw => { + let successInfo = {}; + if (raw.status === _soroban_rpc.SorobanRpc.GetTransactionStatus.SUCCESS) { + var _meta$v3$sorobanMeta; + const meta = _stellarBase.xdr.TransactionMeta.fromXDR(raw.resultMetaXdr, 'base64'); + successInfo = { + ledger: raw.ledger, + createdAt: raw.createdAt, + applicationOrder: raw.applicationOrder, + feeBump: raw.feeBump, + envelopeXdr: _stellarBase.xdr.TransactionEnvelope.fromXDR(raw.envelopeXdr, 'base64'), + resultXdr: _stellarBase.xdr.TransactionResult.fromXDR(raw.resultXdr, 'base64'), + resultMetaXdr: meta, + ...(meta.switch() === 3 && meta.v3().sorobanMeta() !== null && { + returnValue: (_meta$v3$sorobanMeta = meta.v3().sorobanMeta()) === null || _meta$v3$sorobanMeta === void 0 ? void 0 : _meta$v3$sorobanMeta.returnValue() + }) + }; + } + const result = { + status: raw.status, + latestLedger: raw.latestLedger, + latestLedgerCloseTime: raw.latestLedgerCloseTime, + oldestLedger: raw.oldestLedger, + oldestLedgerCloseTime: raw.oldestLedgerCloseTime, + ...successInfo }; - } - const result = { - status: raw.status, - latestLedger: raw.latestLedger, - latestLedgerCloseTime: raw.latestLedgerCloseTime, - oldestLedger: raw.oldestLedger, - oldestLedgerCloseTime: raw.oldestLedgerCloseTime, - ...successInfo - }; - return result; + return result; + }); + } + async _getTransaction(hash) { + return jsonrpc.post(this.serverURL.toString(), 'getTransaction', hash); } /** @@ -348,13 +354,10 @@

lib/server.js

* }); */ async getEvents(request) { - // TODO: It'd be nice if we could do something to infer the types of filter - // arguments a user wants, e.g. converting something like "transfer/*/42" - // into the base64-encoded `ScVal` equivalents by inferring that the first - // is an ScSymbol and the last is a U32. - // - // The difficulty comes in matching up the correct integer primitives. - return jsonrpc.postObject(this.serverURL.toString(), "getEvents", { + return this._getEvents(request).then(_parsers.parseRawEvents); + } + async _getEvents(request) { + return jsonrpc.postObject(this.serverURL.toString(), 'getEvents', { filters: request.filters ?? [], pagination: { ...(request.cursor && { @@ -386,7 +389,7 @@

lib/server.js

* }); */ async getNetwork() { - return await jsonrpc.post(this.serverURL.toString(), "getNetwork"); + return await jsonrpc.post(this.serverURL.toString(), 'getNetwork'); } /** @@ -405,7 +408,7 @@

lib/server.js

* }); */ async getLatestLedger() { - return jsonrpc.post(this.serverURL.toString(), "getLatestLedger"); + return jsonrpc.post(this.serverURL.toString(), 'getLatestLedger'); } /** @@ -451,7 +454,10 @@

lib/server.js

* }); */ async simulateTransaction(transaction) { - return jsonrpc.post(this.serverURL.toString(), "simulateTransaction", transaction.toXDR()).then(_transaction.parseRawSimulation); + return this._simulateTransaction(transaction).then(_parsers.parseRawSimulation); + } + async _simulateTransaction(transaction) { + return jsonrpc.post(this.serverURL.toString(), 'simulateTransaction', transaction.toXDR()); } /** @@ -535,7 +541,7 @@

lib/server.js

throw simResponse.error; } if (!simResponse.result) { - throw new Error("transaction simulation failed"); + throw new Error('transaction simulation failed'); } return (0, _transaction.assembleTransaction)(transaction, passphrase, simResponse).build(); } @@ -584,7 +590,10 @@

lib/server.js

* }); */ async sendTransaction(transaction) { - return await jsonrpc.post(this.serverURL.toString(), "sendTransaction", transaction.toXDR()); + return this._sendTransaction(transaction).then(_parsers.parseRawSendTransaction); + } + async _sendTransaction(transaction) { + return jsonrpc.post(this.serverURL.toString(), 'sendTransaction', transaction.toXDR()); } /** @@ -617,21 +626,21 @@

lib/server.js

* }); */ async requestAirdrop(address, friendbotUrl) { - const account = typeof address === "string" ? address : address.accountId(); + const account = typeof address === 'string' ? address : address.accountId(); friendbotUrl = friendbotUrl || (await this.getNetwork()).friendbotUrl; if (!friendbotUrl) { - throw new Error("No friendbot URL configured for current network"); + throw new Error('No friendbot URL configured for current network'); } try { const response = await _axios.default.post(`${friendbotUrl}?addr=${encodeURIComponent(account)}`); - const meta = _stellarBase.xdr.TransactionMeta.fromXDR(response.data.result_meta_xdr, "base64"); + const meta = _stellarBase.xdr.TransactionMeta.fromXDR(response.data.result_meta_xdr, 'base64'); const sequence = findCreatedAccountSequenceInTransactionMeta(meta); return new _stellarBase.Account(account, sequence); } catch (error) { var _error$response; if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 400) { var _error$response$detai; - if ((_error$response$detai = error.response.detail) !== null && _error$response$detai !== void 0 && _error$response$detai.includes("createAccountAlreadyExist")) { + if ((_error$response$detai = error.response.detail) !== null && _error$response$detai !== void 0 && _error$response$detai.includes('createAccountAlreadyExist')) { // Account already exists, load the sequence number return this.getAccount(account); } @@ -654,7 +663,7 @@

lib/server.js

operations = meta.value().operations(); break; default: - throw new Error("Unexpected transaction meta switch value"); + throw new Error('Unexpected transaction meta switch value'); } for (const op of operations) { for (const c of op.changes()) { @@ -668,7 +677,47 @@

lib/server.js

return data.account().seqNum().toString(); } } - throw new Error("No account created in transaction"); + throw new Error('No account created in transaction'); +} + +// TODO - remove once rpc updated to +// append expiration entry per data LK requested onto server-side response +// https://github.com/stellar/soroban-tools/issues/1010 +function mergeResponseExpirationLedgers(ledgerEntriesResponse, requestedKeys) { + const requestedKeyXdrs = new Set(requestedKeys.map(requestedKey => requestedKey.toXDR('base64'))); + const expirationKeyToRawEntryResult = new Map(); + (ledgerEntriesResponse.entries ?? []).forEach(rawEntryResult => { + if (!rawEntryResult.key || !rawEntryResult.xdr) { + throw new TypeError(`invalid ledger entry: ${JSON.stringify(rawEntryResult)}`); + } + const parsedKey = _stellarBase.xdr.LedgerKey.fromXDR(rawEntryResult.key, 'base64'); + const isExpirationMeta = parsedKey.switch().value === _stellarBase.xdr.LedgerEntryType.expiration().value && !requestedKeyXdrs.has(rawEntryResult.key); + const keyHash = isExpirationMeta ? parsedKey.expiration().keyHash().toString() : (0, _stellarBase.hash)(parsedKey.toXDR()).toString(); + const rawEntry = expirationKeyToRawEntryResult.get(keyHash) ?? rawEntryResult; + if (isExpirationMeta) { + const expirationLedgerSeq = _stellarBase.xdr.LedgerEntryData.fromXDR(rawEntryResult.xdr, 'base64').expiration().expirationLedgerSeq(); + expirationKeyToRawEntryResult.set(keyHash, { + ...rawEntry, + expirationLedgerSeq + }); + } else { + expirationKeyToRawEntryResult.set(keyHash, { + ...rawEntry, + ...rawEntryResult + }); + } + }); + ledgerEntriesResponse.entries = [...expirationKeyToRawEntryResult.values()]; + return ledgerEntriesResponse; +} + +// TODO - remove once rpc updated to +// include expiration entry on responses for any data LK's requested +// https://github.com/stellar/soroban-tools/issues/1010 +function expandRequestIncludeExpirationLedgers(keys) { + return keys.concat(keys.filter(key => key.switch().value !== _stellarBase.xdr.LedgerEntryType.expiration().value).map(key => _stellarBase.xdr.LedgerKey.expiration(new _stellarBase.xdr.LedgerKeyExpiration({ + keyHash: (0, _stellarBase.hash)(key.toXDR()) + })))); }

@@ -681,7 +730,7 @@

lib/server.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/lib_soroban_rpc.js.html b/lib_soroban_rpc.js.html index 9e9770fb..0f936fcb 100644 --- a/lib_soroban_rpc.js.html +++ b/lib_soroban_rpc.js.html @@ -24,7 +24,7 @@
@@ -50,11 +50,10 @@

lib/soroban_rpc.js

/** * @namespace SorobanRpc */ -let SorobanRpc; -exports.SorobanRpc = SorobanRpc; +let SorobanRpc = exports.SorobanRpc = void 0; (function (_SorobanRpc) { - /* Response for jsonrpc method `getLedgerEntries` - */ + /** An XDR-parsed version of {@link RawLedgerEntryResult} */ + /** @see https://soroban.stellar.org/api/methods/getLedgerEntries */ /* Response for jsonrpc method `getNetwork` */ /* Response for jsonrpc method `getLatestLedger` @@ -92,6 +91,10 @@

lib/soroban_rpc.js

return isSimulationSuccess(sim) && 'restorePreamble' in sim && !!sim.restorePreamble.transactionData; } _SorobanRpc.isSimulationRestore = isSimulationRestore; + function isSimulationRaw(sim) { + return !sim._parsed; + } + _SorobanRpc.isSimulationRaw = isSimulationRaw; /** @see https://soroban.stellar.org/api/methods/simulateTransaction#returns */ })(SorobanRpc || (exports.SorobanRpc = SorobanRpc = {}));

@@ -105,7 +108,7 @@

lib/soroban_rpc.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.
diff --git a/lib_transaction.js.html b/lib_transaction.js.html index 1cad6073..879e34fc 100644 --- a/lib_transaction.js.html +++ b/lib_transaction.js.html @@ -24,7 +24,7 @@
@@ -45,10 +45,9 @@

lib/transaction.js

value: true }); exports.assembleTransaction = assembleTransaction; -exports.isSimulationRaw = isSimulationRaw; -exports.parseRawSimulation = parseRawSimulation; var _stellarBase = require("stellar-base"); var _soroban_rpc = require("./soroban_rpc"); +var _parsers = require("./parsers"); /** * Combines the given raw transaction alongside the simulation results. * @@ -69,14 +68,14 @@

lib/transaction.js

* @see {Server.prepareTransaction} */ function assembleTransaction(raw, networkPassphrase, simulation) { - if ("innerTransaction" in raw) { + if ('innerTransaction' in raw) { // TODO: Handle feebump transactions return assembleTransaction(raw.innerTransaction, networkPassphrase, simulation); } if (!isSorobanTransaction(raw)) { - throw new TypeError("unsupported transaction: must contain exactly one " + "invokeHostFunction, bumpFootprintExpiration, or restoreFootprint " + "operation"); + throw new TypeError('unsupported transaction: must contain exactly one ' + 'invokeHostFunction, bumpFootprintExpiration, or restoreFootprint ' + 'operation'); } - let success = parseRawSimulation(simulation); + let success = (0, _parsers.parseRawSimulation)(simulation); if (!_soroban_rpc.SorobanRpc.isSimulationSuccess(success)) { throw new Error(`simulation incorrect: ${JSON.stringify(success)}`); } @@ -97,7 +96,7 @@

lib/transaction.js

networkPassphrase }); switch (raw.operations[0].type) { - case "invokeHostFunction": + case 'invokeHostFunction': // In this case, we don't want to clone the operation, so we drop it. txnBuilder.clearOperations(); const invokeOp = raw.operations[0]; @@ -116,86 +115,14 @@

lib/transaction.js

} return txnBuilder; } - -/** - * Converts a raw response schema into one with parsed XDR fields and a - * simplified interface. - * - * @param raw the raw response schema (parsed ones are allowed, best-effort - * detected, and returned untouched) - * - * @returns the original parameter (if already parsed), parsed otherwise - */ -function parseRawSimulation(sim) { - var _sim$events; - const looksRaw = isSimulationRaw(sim); - if (!looksRaw) { - // Gordon Ramsey in shambles - return sim; - } - - // shared across all responses - let base = { - _parsed: true, - id: sim.id, - latestLedger: sim.latestLedger, - events: ((_sim$events = sim.events) === null || _sim$events === void 0 ? void 0 : _sim$events.map(evt => _stellarBase.xdr.DiagnosticEvent.fromXDR(evt, 'base64'))) ?? [] - }; - - // error type: just has error string - if (typeof sim.error === 'string') { - return { - ...base, - error: sim.error - }; - } - return parseSuccessful(sim, base); -} -function parseSuccessful(sim, partial) { - var _sim$results; - // success type: might have a result (if invoking) and... - const success = { - ...partial, - transactionData: new _stellarBase.SorobanDataBuilder(sim.transactionData), - minResourceFee: sim.minResourceFee, - cost: sim.cost, - ...( - // coalesce 0-or-1-element results[] list into a single result struct - // with decoded fields if present - (((_sim$results = sim.results) === null || _sim$results === void 0 ? void 0 : _sim$results.length) ?? 0 > 0) && { - result: sim.results.map(row => { - return { - auth: (row.auth ?? []).map(entry => _stellarBase.xdr.SorobanAuthorizationEntry.fromXDR(entry, 'base64')), - // if return value is missing ("falsy") we coalesce to void - retval: !!row.xdr ? _stellarBase.xdr.ScVal.fromXDR(row.xdr, 'base64') : _stellarBase.xdr.ScVal.scvVoid() - }; - })[0] - }) - }; - if (!sim.restorePreamble || sim.restorePreamble.transactionData === '') { - return success; - } - - // ...might have a restoration hint (if some state is expired) - return { - ...success, - restorePreamble: { - minResourceFee: sim.restorePreamble.minResourceFee, - transactionData: new _stellarBase.SorobanDataBuilder(sim.restorePreamble.transactionData) - } - }; -} -function isSimulationRaw(sim) { - return !sim._parsed; -} function isSorobanTransaction(tx) { if (tx.operations.length !== 1) { return false; } switch (tx.operations[0].type) { - case "invokeHostFunction": - case "bumpFootprintExpiration": - case "restoreFootprint": + case 'invokeHostFunction': + case 'bumpFootprintExpiration': + case 'restoreFootprint': return true; default: return false; @@ -212,7 +139,7 @@

lib/transaction.js


- Generated by JSDoc 4.0.2 on Thu Sep 14 2023 19:53:35 GMT+0000 (Coordinated Universal Time) using the Minami theme. + Generated by JSDoc 4.0.2 on Wed Nov 15 2023 09:54:37 GMT-0800 (Pacific Standard Time) using the Minami theme.