-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(sapling viewing key): inMemoryViewingKey class A class that holds the viewing key and can be instantiated with a spending key * 1509 state tree (#1599) - Added support for SaplingState - Added unit tests - Added necessary error classes and util methods * feat(sapling): saplingTransactionViewer class (#1601) Allows to retrieve and decrypt sapling transactions and fetch the balance re #1571 * missing bignumber in utils package * Implemented sapling forger and added unit tests (#1723) * Added new `types` file * sapling spending address viewing key 1604 fix branch (#1734) Co-authored-by: Zainen Suzuki <zainensuzuki@Zainens-MacBook-Pro.local> * refactor(taquito and utils): move the format function for taquito package to utils * refactor(integration-tests): accept the memo size as a param for the sapling contract Co-authored-by: Daniele Lisi <22307776+danielelisi@users.noreply.github.com> * feat(taquito): add getSaplingDiffByContract method to the TzReadProvider * feat(sapling): prepare sapling transactions (#1794) * refactor(integration-tests): accept the memo size as a param for the sapling contract * feat(taquito): add getSaplingDiffByContract method to the TzReadProvider * feat(sapling): prepare sapling transactions The SaplingToolkit class allows to prepare shielded transactions, unshielded transactions and sapling transactions based on a spendingkey re #1572 * Added axios dependency * Added bip39 dependency to integration tests * Support instantiation of InMemoryViewingKey with encrypted sk * docs(sapling): documentation for the sapling package * Add info on the README * refactor(read-adapter): remove the context from the constructor Takes a rpcClient in the constructor instead of a context. Context is an internal class that should not be available to the users. BREAKING CHANGE: RpcReadAdapter needs a RpcClient in the constructor * fix(sapling): fix for using the package on the web Fetch and bundle the zcash sapling params in the package * Removed sapling params files as their size are very large * Upgrade to @airgap/sapling-wasm version having fix for node * Reduce bundle size * Ignore lint rule for generated files sapling params * Fix path * test(integration tests): sapling multiple states test An integration test to interact with a contract having 2 sapling pools re #1825 * Make the sapling examples runnable on the website * feat(sapling): support proof generation from provingkey (#1837) * feat(sapling): support proof generation from provingkey Implemented an InMemorySpendingKey class that allows producing proof independently from the spending key. Did some refactoring and renaming also. * Updated README and added load test * upgrade airgap/sapling-wasm package * import sapling package in example folder Co-authored-by: Davis Sawali <davis.sawali@ecadlabs.com> Co-authored-by: Zainen <72581075+zainen@users.noreply.github.com> Co-authored-by: Zainen Suzuki <zainensuzuki@Zainens-MacBook-Pro.local> Co-authored-by: Daniele Lisi <22307776+danielelisi@users.noreply.github.com>
- Loading branch information
1 parent
043d892
commit bbd425f
Showing
129 changed files
with
207,884 additions
and
11,575 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
title: InMemorySpendingKey | ||
author: Zainen Suzuki | ||
--- | ||
|
||
# Sapling Spending Key Instantiation | ||
|
||
:::caution Warning | ||
**Storing private keys in memory is suitable for development workflows but risky for | ||
production use-cases! Use the `InMemorySpendingKey` appropriately given your risk profile** | ||
::: | ||
|
||
### From Mnemonic | ||
|
||
Instantiation of a `InMemorySpendingkey` from Mnemonic does not require a password as it is only used to change an unencrypted `sask...` to an encrypted `MMXj...` spending key or vice versa | ||
|
||
Params: | ||
- `mnemonic` list of words | ||
- `derivationPath` tezos current standard 'm/' | ||
|
||
Returns: | ||
- InMemorySpendingKey class instantiated | ||
|
||
|
||
|
||
```js | ||
const SaplingKeyProvider = await InMemorySpendingKey.fromMnemonic([ | ||
'leopard', 'crouch', 'simple', 'blind', 'castle', 'they', | ||
'elder', 'enact', 'slow', 'rate', 'mad', 'blanket', | ||
'saddle', 'tail', 'silk', 'fury', 'quarter', 'obscure', | ||
'interest', 'exact', 'veteran', 'volcano', 'fabric', 'cherry' | ||
`], | ||
'm/' | ||
) // derivationPath by current standard is 'm/' | ||
``` | ||
|
||
### From Encrypted Spending Key | ||
|
||
If the spending key is encrypted prefixed with `MMXj...` then a password is required to decrypt to a unencrypted Spending Key `sask...` | ||
|
||
Params: | ||
- `spendingKey` unencrypted sask... or encrypted MMXj... | ||
- `password` required for MMXj encrypted keys | ||
|
||
```js | ||
const SaplingKeyProvider = new InMemorySpendingKey( | ||
'MMXjN99mhomTm1Y5nQt8NfwEKTHWugsLtucX7oWrpsJd99qxGYJWP5aMb3t8zZaoKHQ898bLu9dwpog71bnjiDZfS9J9hWnTLCGm4fAjKKYeRuwTgCRjSdsP9znCPBUpCvyxeEFvUfamA5URrp8c7AaooAkobLW1PjNh2vjHobtiyNVTEtyTUWTLcjdxaiPbQWs3NaWvcb5Qr6z9MHhKrYNBHmsd9HBeRB2rVnvvL7pMc8f8zqyuXtmAuzMhiqPz3B4BRzuc8a2jkkoL14', | ||
'test' | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
title: InMemoryViewingKey | ||
author: Roxane Letourneau | ||
--- | ||
|
||
The `InMemoryViewingKey` class can be instantiated from a viewing or spending key. | ||
|
||
### Instantiation from a viewing key: | ||
|
||
```js | ||
import { InMemoryViewingKey } from '@taquito/sapling'; | ||
const inMemoryViewingKey = new InMemoryViewingKey( | ||
'000000000000000000977d725fc96387e8ec1e603e7ae60c6e63529fb84e36e126770e9db9899d7f2344259fd700dc80120d3c9ca65d698f6064043b048b079caa4f198aed96271740b1d6fd523d71b15cd0b3d75644afbe9abfedb6883e299165665ab692c14ca5c835c61a0e53de553a751c78fbc42d5e7eca807fd441206651c84bf88de803efba837583145a5f338b1a7af8a5f9bec4783054f9d063d365f2352f72cbced95e0a' | ||
); | ||
``` | ||
|
||
### Instantiation from an unencrypted spending key: | ||
|
||
```js live noInline | ||
import { InMemoryViewingKey } from '@taquito/sapling'; | ||
|
||
InMemoryViewingKey.fromSpendingKey( | ||
'sask27SLmU9herddHz4qFJBLMjWYMbJF8RtS579w9ej9mfCYK7VUdyCJPHK8AzW9zMsopGZEkYeNjAY7Zz1bkM7CGu8eKLzrjBLTMC5wWJDhxiK91ahA29rhDRsHdJDV2u2jFwb2MNUix8JW7sAkAqYVaJpCehTBPgRQ1KqKwqqUaNmuD8kazd4Q8MCWmgbWs21Yuomdqyi9FLigjRp7oY4m5adaVU19Nj1AHvsMY2tePeU2L', | ||
).then((inMemoryViewingKey) => { | ||
const viewingKey = inMemoryViewingKey.getFullViewingKey() | ||
println(`The viewing key is ${viewingKey.toString('hex')}`); | ||
}) | ||
.catch((error) => println(`Error: ${JSON.stringify(error, null, 2)}`)); | ||
|
||
``` | ||
|
||
### Instantiation from an encrypted spending key: | ||
|
||
```js live noInline | ||
import { InMemoryViewingKey } from '@taquito/sapling'; | ||
|
||
InMemoryViewingKey.fromSpendingKey( | ||
'MMXjN99mhomTm1Y5nQt8NfwEKTHWugsLtucX7oWrpsJd99qxGYJWP5aMb3t8zZaoKHQ898bLu9dwpog71bnjiDZfS9J9hWnTLCGm4fAjKKYeRuwTgCRjSdsP9znCPBUpCvyxeEFvUfamA5URrp8c7AaooAkobLW1PjNh2vjHobtiyNVTEtyTUWTLcjdxaiPbQWs3NaWvcb5Qr6z9MHhKrYNBHmsd9HBeRB2rVnvvL7pMc8f8zqyuXtmAuzMhiqPz3B4BRzuc8a2jkkoL14', | ||
'test' // password | ||
).then((inMemoryViewingKey) => { | ||
const viewingKey = inMemoryViewingKey.getFullViewingKey() | ||
println(`The viewing key is ${viewingKey.toString('hex')}`); | ||
}) | ||
.catch((error) => println(`Error: ${JSON.stringify(error, null, 2)}`)); | ||
|
||
``` | ||
|
||
## How to retrieve payment addresses from the viewing key | ||
|
||
The `InMemoryViewingKey` class has a method named `getAddress`, allowing to derive addresses (zet) from the viewing key. An index can be specified as a parameter, or the default value `0` will be used. | ||
|
||
```js live noInline | ||
import { InMemoryViewingKey } from '@taquito/sapling'; | ||
|
||
const inMemoryViewingKey = new InMemoryViewingKey( | ||
'000000000000000000977d725fc96387e8ec1e603e7ae60c6e63529fb84e36e126770e9db9899d7f2344259fd700dc80120d3c9ca65d698f6064043b048b079caa4f198aed96271740b1d6fd523d71b15cd0b3d75644afbe9abfedb6883e299165665ab692c14ca5c835c61a0e53de553a751c78fbc42d5e7eca807fd441206651c84bf88de803efba837583145a5f338b1a7af8a5f9bec4783054f9d063d365f2352f72cbced95e0a' | ||
); | ||
|
||
inMemoryViewingKey.getAddress() | ||
.then((address) => println(`The address is ${JSON.stringify(address, null, 2)}`)) | ||
.catch((error) => println(`Error: ${JSON.stringify(error, null, 2)}`)); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { TezosToolkit, RpcReadAdapter } from '@taquito/taquito'; | ||
import { InMemorySigner } from '@taquito/signer'; | ||
import { InMemorySpendingKey, SaplingToolkit } from '@taquito/sapling'; | ||
//import { singleSaplingStateContractJProtocol } from '../integration-tests/data/single_sapling_state_contract_jakarta_michelson'; | ||
|
||
const provider = 'https://kathmandunet.ecadinfra.com/'; | ||
const numberOfSaplingTx = 1000; | ||
let totalTime = 0; | ||
|
||
async function example() { | ||
try { | ||
const tezos = new TezosToolkit(provider); | ||
tezos.setSignerProvider(new InMemorySigner('spsk1m4s7kPegWrAHVVJQ8H64UvtojtopmmAfkr64UYyAMDHD4pGDA')) | ||
console.log(await tezos.signer.publicKeyHash()) | ||
|
||
/* const saplingContractOrigination = await tezos.contract.originate({ | ||
code: singleSaplingStateContractJProtocol(), | ||
init: '{}' | ||
}); */ | ||
|
||
//const saplingContract = await saplingContractOrigination.contract(); | ||
const saplingContract = await tezos.contract.at('KT1SmRBZvitJKeW6G491FUyGKHvdUrQtZ5CS'); | ||
console.log(saplingContract.address); | ||
|
||
const aliceInMemorySpendingKey = new InMemorySpendingKey('sask27SLmU9herddHz4qFJBLMjWYMbJF8RtS579w9ej9mfCYK7VUdyCJPHK8AzW9zMsopGZEkYeNjAY7Zz1bkM7CGu8eKLzrjBLTMC5wWJDhxiK91ahA29rhDRsHdJDV2u2jFwb2MNUix8JW7sAkAqYVaJpCehTBPgRQ1KqKwqqUaNmuD8kazd4Q8MCWmgbWs21Yuomdqyi9FLigjRp7oY4m5adaVU19Nj1AHvsMY2tePeU2L'); | ||
const aliceSaplingToolkit = new SaplingToolkit({ saplingSigner: aliceInMemorySpendingKey }, { contractAddress: saplingContract.address, memoSize: 8 }, new RpcReadAdapter(tezos.rpc)); | ||
const aliceInMemoryViewingKey = await aliceInMemorySpendingKey.getSaplingViewingKeyProvider(); | ||
const alicePaymentAddress = (await aliceInMemoryViewingKey.getAddress()).address; | ||
|
||
const shieldedTx = await aliceSaplingToolkit.prepareShieldedTransaction([{ | ||
to: alicePaymentAddress, | ||
amount: 5, | ||
memo: 'First Tx' | ||
}]) | ||
|
||
const op = await saplingContract.methods.default([shieldedTx]).send({ amount: 5 }); | ||
await op.confirmation(); | ||
|
||
// loop to create multiple sapling transactions (numberOfSaplingTx) and log the time taken to prepare it | ||
for (let i = 0; i < numberOfSaplingTx; i++) { | ||
|
||
const start = Date.now(); | ||
|
||
const tx = await aliceSaplingToolkit.prepareSaplingTransaction([{ | ||
to: 'zet14CMN2T4x1f8sgXeAGWQwczSf6SJ8bm8nyP2Tg7HJn2VmtPtB2nE2q7MMgdmMEwpGQ', | ||
amount: 2, | ||
memo: `tx ${i}`, | ||
mutez: true | ||
}]) | ||
|
||
const millis = Date.now() - start; | ||
const time = Math.floor(millis / 1000) | ||
console.log(`seconds elapsed for tx ${i} = ${time}`); | ||
totalTime += time | ||
|
||
const op = await saplingContract.methods.default([tx]).send(); | ||
await op.confirmation(); | ||
|
||
} | ||
|
||
const aliceTxViewer = await aliceSaplingToolkit.getSaplingTransactionViewer() | ||
const balance = await aliceTxViewer.getBalance(); | ||
console.log('balance', balance.toString()); | ||
console.log('average', totalTime / numberOfSaplingTx) | ||
|
||
} catch (ex) { | ||
console.error(ex); | ||
} | ||
} | ||
|
||
example(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
integration-tests/data/single_sapling_state_contract_jakarta_michelson.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.