Skip to content

Commit

Permalink
Merge branch 'release/v2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
onetechnical committed May 8, 2023
2 parents 7fa7330 + 41169be commit e3bcc3b
Show file tree
Hide file tree
Showing 64 changed files with 3,269 additions and 1,985 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ commands:
<< parameters.sudo >> apt -y update
<< parameters.sudo >> apt -y install curl make git build-essential jq unzip
- node/install:
node-version: '14'
node-version: '16'
- run:
name: npm ci
command: |
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/pr-type-category.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ jobs:
labels: "New Feature, Enhancement, Bug-Fix, Not-Yet-Enabled, Skip-Release-Notes"

- name: "Checking for PR Category in PR title. Should be like '<category>: <pr title>'."
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
if [[ ! "${{ github.event.pull_request.title }}" =~ ^.{2,}\:.{2,} ]]; then
if [[ ! "$PR_TITLE" =~ ^.{2,}\:.{2,} ]]; then
echo "## PR Category is missing from PR title. Please add it like '<category>: <pr title>'." >> GITHUB_STEP_SUMMARY
exit 1
fi
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
# v2.3.0

## What's Changed

### Bugfixes

- Docs: Repair the links in the docs to developer.algorand.org by @bbroder-algo in https://github.com/algorand/js-algorand-sdk/pull/755
- Fix: Allow nonParticipation flag to be a boolean by @barnjamin in https://github.com/algorand/js-algorand-sdk/pull/757
- BugFix: Min fee sp fix by @barnjamin in https://github.com/algorand/js-algorand-sdk/pull/760

### New Features

- Simulation: Lift log limits option in SimulateRequest by @ahangsu in https://github.com/algorand/js-algorand-sdk/pull/768

### Enhancements

- Docs: Examples by @barnjamin in https://github.com/algorand/js-algorand-sdk/pull/754
- API: Support updated simulate endpoint by @jasonpaulos in https://github.com/algorand/js-algorand-sdk/pull/764
- algod: Add blockOffsetTimestamp, syncRound APIs to algod client by @Eric-Warehime in https://github.com/algorand/js-algorand-sdk/pull/769
- node: Drop support for node v14, npm audit fix by @Eric-Warehime in https://github.com/algorand/js-algorand-sdk/pull/773
- client: Export token header types by @Eric-Warehime in https://github.com/algorand/js-algorand-sdk/pull/772
- DevOps: Add CODEOWNERS to restrict workflow editing by @onetechnical in https://github.com/algorand/js-algorand-sdk/pull/775
- Docs: Update README & FAQ by @jasonpaulos in https://github.com/algorand/js-algorand-sdk/pull/774

## New Contributors

- @bbroder-algo made their first contribution in https://github.com/algorand/js-algorand-sdk/pull/755

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

# v2.2.0

## What's Changed
Expand Down
2 changes: 2 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.github/ @algorand/dev
.circleci/ @algorand/dev
50 changes: 0 additions & 50 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,6 @@ In prior versions, the browser bundles were made available in the `dist` directo

Yes! If you would instead prefer to host the package yourself, a minified browser bundle can be found in the `dist/browser/` folder of the published npm package starting with version 1.9.0.

## It says `Error: Can't resolve....` in the sdk

This kind of errors is usually seen in Webpack 5 or Vite projects. You will need to install additional polyfill packages.

#### Webpack 5 projects

Typically, with Webpack 5 you would see:

```
Module not found: Error: Can't resolve 'crypto'
ERROR in ./node_modules/algosdk/dist/browser/algosdk.min.js 7471:55-72
```

Webpack 5 no longer auto-polyfills some of the node modules used by this sdk. You will have to polyfill them to fix any errors regarding missing modules.

#### Vite projects

With Vite, you would see:

```
Uncaught ReferenceError: Buffer is not defined
```

You will have to install `buffer` as dependency.

In `index.html`, add the following:

```html
<script type="module">
import { Buffer } from 'buffer';
window.Buffer = Buffer;
</script>
```

To utilize the Buffer polyfill in production builds, in `vite.config.js`, add:

```js
import inject from '@rollup/plugin-inject';

export default defineConfig({
...,
build: {
rollupOptions: {
plugins: [inject({ Buffer: ['buffer', 'Buffer'] })],
},
},
...
});
```

## How do I generate the SRI hash of `algosdk.min.js`?

The SRI hash of `algosdk.min.js` is the base64 string after `sha384-` in the `integrity` attribute of the `<script>` tag used to import `algosdk.min.js`.
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ docker-run:
docker ps -a
docker run -it --network host js-sdk-testing:latest

smoke-test-examples:
cd examples && bash smoke_test.sh && cd -

docker-test: harness docker-build docker-run

format:
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# js-algorand-sdk

[![Build Status](https://travis-ci.com/algorand/js-algorand-sdk.svg?branch=master)](https://travis-ci.com/algorand/js-algorand-sdk) [![npm version](https://badge.fury.io/js/algosdk.svg)](https://www.npmjs.com/package/algosdk)
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/algorand/js-algorand-sdk/tree/develop.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/algorand/js-algorand-sdk/tree/develop) [![npm version](https://badge.fury.io/js/algosdk.svg)](https://www.npmjs.com/package/algosdk)

AlgoSDK is the official JavaScript library for communicating with the Algorand network. It's designed for modern browsers and Node.js.

Expand All @@ -14,16 +14,14 @@ $ npm install algosdk

> This package provides TypeScript types, but you will need [TypeScript](https://www.typescriptlang.org/) version 4.2 or higher to use them properly.
For errors in Webpack 5 or Vite projects, you will need to [install extra dependencies](FAQ.md#it-says-error-cant-resolve-in-the-sdk).

### Browser

Include a minified browser bundle directly in your HTML like so:

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

```html
<script
src="https://cdn.jsdelivr.net/npm/algosdk@v2.2.0/dist/browser/algosdk.min.js"
integrity="sha384-znctcpmM127r1SpRzV9waJMVOQahRDY2qodrS+rtd0HaYNPPCxDeaXTEu2safkCy"
src="https://cdn.jsdelivr.net/npm/algosdk@v2.3.0/dist/browser/algosdk.min.js"
integrity="sha384-fgeAt2Eu1e4m+Ci+iZyaZGF3GrvtcavVyjUEFuHyhiRjMi60ape5AxIWR08Js1S9"
crossorigin="anonymous"
></script>
```
Expand Down
9 changes: 9 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Algorand JavaScript SDK Examples

This directory contains examples of how to use the Algorand JavaScript SDK.

Assuming a sandbox node is running locally, any example can be run with the following command:

```sh
ts-node <example_name>.ts
```
101 changes: 29 additions & 72 deletions examples/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ async function main() {
const accounts = await getLocalAccounts();
const suggestedParams = await client.getTransactionParams().do();

const acct1 = accounts[0];
const acct2 = accounts[1];

// 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);
// restore 25-word mnemonic from a string
// Note the mnemonic should _never_ appear in your source code
const mnemonic =
'creek phrase island true then hope employ veteran rapid hurdle above liberty tissue connect alcohol timber idle ten frog bulb embody crunch taxi abstract month';
const recoveredAccount = algosdk.mnemonicToSecretKey(mnemonic);
console.log('Recovered mnemonic account: ', recoveredAccount.addr);
// example: ACCOUNT_RECOVER_MNEMONIC

const funder = accounts[0];
Expand All @@ -24,6 +28,7 @@ async function main() {
const signerAccounts: algosdk.Account[] = [];
signerAccounts.push(algosdk.generateAccount());
signerAccounts.push(algosdk.generateAccount());
signerAccounts.push(algosdk.generateAccount());

// multiSigParams is used when creating the address and when signing transactions
const multiSigParams = {
Expand Down Expand Up @@ -80,83 +85,35 @@ async function main() {
// 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
// Note any transaction type can be used to rekey an account
const rekeyTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: originalAccount.addr,
to: originalAccount.addr,
from: acct1.addr,
to: acct1.addr,
amount: 0,
suggestedParams,
rekeyTo: newSigner.addr, // set the rekeyTo field to the new signer
rekeyTo: acct2.addr, // set the rekeyTo field to the new signer
});

await client.sendRawTransaction(rekeyTxn.signTxn(originalAccount.sk)).do();
await client.sendRawTransaction(rekeyTxn.signTxn(acct1.privateKey)).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,
}
);
const acctInfo = await client.accountInformation(acct1.addr).do();

// 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
);
console.log(`Account Info: ${acctInfo} Auth Addr: ${acctInfo['auth-addr']}`);
// example: ACCOUNT_REKEY

// the transaction is from originalAccount, but signed with newSigner private key

const rekeyBack = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: acct1.addr,
to: acct1.addr,
amount: 0,
suggestedParams,
rekeyTo: acct1.addr,
});
await client.sendRawTransaction(rekeyBack.signTxn(acct2.privateKey)).do();
await algosdk.waitForConfirmation(client, rekeyBack.txID().toString(), 3);
}

main();
Loading

0 comments on commit e3bcc3b

Please sign in to comment.