Skip to content

Commit

Permalink
Merge branch 'release/v2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
algobarb committed Mar 23, 2023
2 parents 1fa884d + cab20e9 commit 7fa7330
Show file tree
Hide file tree
Showing 51 changed files with 2,203 additions and 1,197 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
npm run docs
touch docs/.nojekyll
- gh-pages/deploy:
ssh-fingerprints: '75:f5:ad:46:65:a5:22:81:f7:20:ca:74:fb:c6:57:d1'
ssh-fingerprints: '67:e9:d0:1a:e5:98:06:4d:fc:68:32:02:8e:ea:36:3a'
build-dir: docs
commit-message: 'Automated docs update'

Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# v2.2.0

## What's Changed

### Bugfixes

- bugfix: Satisfy typescript constraints by @aorumbayev in https://github.com/algorand/js-algorand-sdk/pull/741
- algod: Minor improvements to simulation support by @jasonpaulos in https://github.com/algorand/js-algorand-sdk/pull/749

### Enhancements

- CICD: Update ssh fingerprint for gh-pages by @algobarb in https://github.com/algorand/js-algorand-sdk/pull/745
- Docs: add examples to be pulled in for docs by @joe-p in https://github.com/algorand/js-algorand-sdk/pull/747
- algod: Simulate Endpoint by @algochoi in https://github.com/algorand/js-algorand-sdk/pull/743

## New Contributors

- @aorumbayev made their first contribution in https://github.com/algorand/js-algorand-sdk/pull/741

**Full Changelog**: https://github.com/algorand/js-algorand-sdk/compare/v2.1.0...v2.2.0

# v2.1.0

## What's Changed
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Include a minified browser bundle directly in your HTML like so:

```html
<script
src="https://unpkg.com/algosdk@v2.1.0/dist/browser/algosdk.min.js"
integrity="sha384-SwM9TdxjIFpIT2FUfchrQvtwi748UI0q12Zi32yd6BM8D/lCTumPhw0+BrPC0yd0"
src="https://unpkg.com/algosdk@v2.2.0/dist/browser/algosdk.min.js"
integrity="sha384-znctcpmM127r1SpRzV9waJMVOQahRDY2qodrS+rtd0HaYNPPCxDeaXTEu2safkCy"
crossorigin="anonymous"
></script>
```
Expand All @@ -32,8 +32,8 @@ or

```html
<script
src="https://cdn.jsdelivr.net/npm/algosdk@v2.1.0/dist/browser/algosdk.min.js"
integrity="sha384-SwM9TdxjIFpIT2FUfchrQvtwi748UI0q12Zi32yd6BM8D/lCTumPhw0+BrPC0yd0"
src="https://cdn.jsdelivr.net/npm/algosdk@v2.2.0/dist/browser/algosdk.min.js"
integrity="sha384-znctcpmM127r1SpRzV9waJMVOQahRDY2qodrS+rtd0HaYNPPCxDeaXTEu2safkCy"
crossorigin="anonymous"
></script>
```
Expand Down
70 changes: 0 additions & 70 deletions examples/README.md

This file was deleted.

162 changes: 162 additions & 0 deletions examples/accounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
/* eslint-disable no-promise-executor-return */
/* eslint-disable no-console */
import algosdk from '../src';
import { getLocalAlgodClient, getLocalAccounts } from './utils';

async function main() {
const client = getLocalAlgodClient();
const accounts = await getLocalAccounts();
const suggestedParams = await client.getTransactionParams().do();

// example: ACCOUNT_RECOVER_MNEMONIC
// restore 25-word mnemonic from environment variable
const mnemonicAccount = algosdk.mnemonicToSecretKey(
process.env.SAMPLE_MNEMONIC!
);
console.log('Recovered mnemonic account: ', mnemonicAccount.addr);
// example: ACCOUNT_RECOVER_MNEMONIC

const funder = accounts[0];

// example: MULTISIG_CREATE
const signerAccounts: algosdk.Account[] = [];
signerAccounts.push(algosdk.generateAccount());
signerAccounts.push(algosdk.generateAccount());

// multiSigParams is used when creating the address and when signing transactions
const multiSigParams = {
version: 1,
threshold: 2,
addrs: signerAccounts.map((a) => a.addr),
};
const multisigAddr = algosdk.multisigAddress(multiSigParams);

console.log('Created MultiSig Address: ', multisigAddr);
// example: MULTISIG_CREATE

const fundMsigTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: funder.addr,
to: multisigAddr,
amount: 1_000_000,
suggestedParams,
});

await client.sendRawTransaction(fundMsigTxn.signTxn(funder.privateKey)).do();
await algosdk.waitForConfirmation(client, fundMsigTxn.txID().toString(), 3);

// example: MULTISIG_SIGN
const msigTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: multisigAddr,
to: funder.addr,
amount: 100,
suggestedParams,
});

// First signature uses signMultisigTransaction
const msigWithFirstSig = algosdk.signMultisigTransaction(
msigTxn,
multiSigParams,
signerAccounts[0].sk
).blob;

// Subsequent signatures use appendSignMultisigTransaction
const msigWithSecondSig = algosdk.appendSignMultisigTransaction(
msigWithFirstSig,
multiSigParams,
signerAccounts[1].sk
).blob;

await client.sendRawTransaction(msigWithSecondSig).do();
await algosdk.waitForConfirmation(client, msigTxn.txID().toString(), 3);
// example: MULTISIG_SIGN

// example: ACCOUNT_GENERATE
const generatedAccount = algosdk.generateAccount();
const passphrase = algosdk.secretKeyToMnemonic(generatedAccount.sk);
console.log(`My address: ${generatedAccount.addr}`);
console.log(`My passphrase: ${passphrase}`);
// example: ACCOUNT_GENERATE

// example: ACCOUNT_REKEY
// create and fund a new account that we will eventually rekey
const originalAccount = algosdk.generateAccount();
const fundOriginalAccount = algosdk.makePaymentTxnWithSuggestedParamsFromObject(
{
from: funder.addr,
to: originalAccount.addr,
amount: 1_000_000,
suggestedParams,
}
);

await client
.sendRawTransaction(fundOriginalAccount.signTxn(funder.privateKey))
.do();
await algosdk.waitForConfirmation(
client,
fundOriginalAccount.txID().toString(),
3
);

// authAddr is undefined by default
const originalAccountInfo = await client
.accountInformation(originalAccount.addr)
.do();
console.log(
'Account Info: ',
originalAccountInfo,
'Auth Addr: ',
originalAccountInfo['auth-addr']
);

// create a new account that will be the new auth addr
const newSigner = algosdk.generateAccount();
console.log('New Signer Address: ', newSigner.addr);

// rekey the original account to the new signer via a payment transaction
const rekeyTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: originalAccount.addr,
to: originalAccount.addr,
amount: 0,
suggestedParams,
rekeyTo: newSigner.addr, // set the rekeyTo field to the new signer
});

await client.sendRawTransaction(rekeyTxn.signTxn(originalAccount.sk)).do();
await algosdk.waitForConfirmation(client, rekeyTxn.txID().toString(), 3);

const originalAccountInfoAfterRekey = await client
.accountInformation(originalAccount.addr)
.do();
console.log(
'Account Info: ',
originalAccountInfoAfterRekey,
'Auth Addr: ',
originalAccountInfoAfterRekey['auth-addr']
);

// form new transaction from rekeyed account
const txnWithNewSignerSig = algosdk.makePaymentTxnWithSuggestedParamsFromObject(
{
from: originalAccount.addr,
to: funder.addr,
amount: 100,
suggestedParams,
}
);

// the transaction is from originalAccount, but signed with newSigner private key
const signedTxn = txnWithNewSignerSig.signTxn(newSigner.sk);

await client.sendRawTransaction(signedTxn).do();
await algosdk.waitForConfirmation(
client,
txnWithNewSignerSig.txID().toString(),
3
);
// example: ACCOUNT_REKEY
}

main();
Loading

0 comments on commit 7fa7330

Please sign in to comment.