Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ETH/POL): Added support for ETH and POL/matic wallets. #9

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
**cache**
**logs**
**.DS_Store**
test.js
Bobinstein marked this conversation as resolved.
Show resolved Hide resolved
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Inspired by the [cookbook github action deployment guide](https://cookbook.arwea
- **Bundle Deployment:** Automatically bundles your JS code and deploys it to Arweave.
- **ArNS Update:** Updates ArNS with the new transaction ID each time new content is deployed.
- **Automated Workflow:** Integrates with GitHub Actions for continuous deployment directly from your repository.
- **Cross-chain support:** Upload data to Arweave and update ArNS using Arweave, Eth, or POL/Matic wallets.

### Installation
Install the package using npm:
Expand All @@ -20,7 +21,9 @@ Before using `permaweb-deploy`, you must:
```bash
base64 -i wallet.json | pbcopy
```
3. Ensure that the secret name for the encoded wallet is `DEPLOY_KEY`.
2. Ensure that the secret name for the encoded wallet is `DEPLOY_KEY`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought here, would be preferable to store as json string. B64 encoding doesnt actually gain any protection - its still a string, just like a json string, and requires more work to decode it.

Copy link

@atticusofsparta atticusofsparta Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And considering eth and pol wallets dont use b64 encoding... well it seems even stranger to still have this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but updating the required method for providing an Arweave wallet's jwk would be a major breaking change. It should be discussed in more detail with the repo owner directly before any community prs are made to address it.

Copy link

@atticusofsparta atticusofsparta Dec 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@twilson63 wdyt? I think either we stick to b64 encoding at all times or revert it for arweave addresses.


**NOTE:** ETH and POL/Matic wallets should use their private key, ***WITHOUT*** base64 encoding for `DEPLOY_KEY`

### Usage
To deploy your application, ensure you have a build script and a deployment script in your `package.json`:
Expand All @@ -34,8 +37,38 @@ To deploy your application, ensure you have a build script and a deployment scri

Replace `<ANT_PROCESS>` with your actual ANT process.

#### `--deploy-folder`

The default folder to upload is `./dist`, you can specify a different folder path using the `--deploy-folder` flag:

```bash
permaweb-deploy --ant-process <ANT_PROCESS> --deploy-folder "./next"
```

#### Ethereum and POL/Matic

Permaweb-deploy defaults to uploading with an Arweave Wallet. You can specify an ETH or POL/Matic wallet by providing a `-e` (`--ethereum`) flag for ETH or a `-p` (`--pol`) flag for POL/Matic.

Providing both `-e` and `-p` flags will result in an error.

The `DEPLOY_KEY` environmental variable must be set to the private key of the ETH or POL/Matic wallet, without any additional encoding.

**NOTE:** All uploads via Permaweb-deploy are paid for using Turbo Credits, you cannot pay for an upload using the native token for ETH or POL/Matic directly. Get Turbo Credits at [turbo-topup.com](https://turbo-topup.com/)

#### Undernames

Permaweb-deploy can update undername records for an ArNS name instead of the top level name. That is, you can deploy your project to `this-project_my-name` where `this-project` is an undername on the ArNS name `my-name`.

This is done by specifying the undername using the `--undername` flag:

```bash
permaweb-deploy --ant-process <ANT_PROCESS> --undername "this-project"
```

### GitHub Actions Workflow

To automate the deployment, set up a GitHub Actions workflow as follows:

```yaml
name: publish

Expand Down Expand Up @@ -66,5 +99,5 @@ DEPLOY_KEY=$(base64 -i wallet.json) npx permaweb-deploy --ant-process <ANT_PROCE

### Important Notes
- **Security:** Always use a dedicated wallet for deployments to minimize risk.
- **Wallet Key:** The wallet must be base64 encoded to be used in the deployment script.
- **Wallet Key:** Arweave wallets must be base64 encoded to be used in the deployment script. Ethereum and POL/Matic wallets should use their raw private key.
- **ANT Process:** The ANT process must be passed at runtime to associate your deployment with a specific ANT process on AO.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"permaweb-deploy": "./dist/index.js"
},
"dependencies": {
"@ar.io/sdk": "^2.2.5",
"@ardrive/turbo-sdk": "^1.17.0",
"@ar.io/sdk": "^3.0.0",
"@ardrive/turbo-sdk": "^1.21.0",
"mime-types": "^2.1.35",
"yargs": "17.7.2"
},
Expand Down
86 changes: 76 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#!/usr/bin/env node

import { ANT, ArweaveSigner } from '@ar.io/sdk';
import { EthereumSigner, TurboFactory } from '@ardrive/turbo-sdk';
import fs from 'fs';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

import TurboDeploy from './turbo';

const argv = yargs(hideBin(process.argv))
.option('ant-process', {
alias: 'a',
type: 'string',
description: 'The ANT process',
description: 'The ANT process.',
demandOption: true,
})
.option('deploy-folder', {
Expand All @@ -25,6 +24,16 @@ const argv = yargs(hideBin(process.argv))
type: 'string',
description: 'ANT undername to update.',
default: '@',
})
.option('eth', {
alias: 'e',
type: 'boolean',
description: 'Connect with an ETH wallet instead of an Arweve wallet.',
})
.option('pol', {
Bobinstein marked this conversation as resolved.
Show resolved Hide resolved
alias: 'p',
type: 'boolean',
description: 'Connect with a POL/MATIC wallet instead of an Arweave wallet.',
}).argv;

const DEPLOY_KEY = process.env.DEPLOY_KEY;
Expand Down Expand Up @@ -67,29 +76,86 @@ export function getTagValue(list, name) {
return;
}

let jwk = JSON.parse(Buffer.from(DEPLOY_KEY, 'base64').toString('utf-8'));
// Throw an error if both --eth and --pol are true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a very scalable method i think. An argument of sig-type or something that passes in values like would remove the need for these checks. Ideally it matches up with the arbundles signature config so we can map from their, but we can also use named values like polygon or ethereum to map to the right signers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand. We want deployments to default to Arweave unless something else is explicitly specified. Requiring a declaration of signer type in all cases would be a major breaking change.

Can you clarify what you're requesting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the -e and -p flags to use a single --sig-type flag instead, that defaults to arweave, and only valid signer types may be provided.

if (argv.eth && argv.pol) {
console.error('Error: Cannot deploy with both ETH and POL.');
process.exit(1); // Exit with an error code
}

let jwk;
if (argv.pol || argv.eth) jwk = DEPLOY_KEY;
else {
jwk = JSON.parse(Buffer.from(DEPLOY_KEY, 'base64').toString('utf-8'));
}

try {
const manifestId = await TurboDeploy(argv, jwk);
const signer = new ArweaveSigner(jwk);
let signer;
let token;

// Creates proper signer based on wallet type.
switch (true) {
Bobinstein marked this conversation as resolved.
Show resolved Hide resolved
case argv.eth:
signer = new EthereumSigner(jwk);
token = 'ethereum';
break;
case argv.pol:
signer = new EthereumSigner(jwk);
token = 'pol';
break;
default:
signer = new ArweaveSigner(jwk);
token = 'arweave';
break;
Bobinstein marked this conversation as resolved.
Show resolved Hide resolved
}

const turbo = TurboFactory.authenticated({
signer: signer,
token: token,
});

const uploadResult = await turbo.uploadFolder({
folderPath: argv['deploy-folder'],
dataItemOpts: {
tags: [
{
name: 'App-Name',
value: 'Permaweb-Deploy',
},
// prevents identical transaction Ids from eth wallets
{
name: 'anchor',
value: new Date().toISOString(),
},
],
},
});

const manifestId = uploadResult.manifestResponse.id;

const ant = ANT.init({ processId: ANT_PROCESS, signer });
Bobinstein marked this conversation as resolved.
Show resolved Hide resolved

// Update the ANT record (assumes the JWK is a controller or owner)
// Update the ANT record (assumes the signer is a controller or owner)
await ant.setRecord(
{
undername: argv.undername,
transactionId: manifestId,
ttlSeconds: 3600,
},{
},
{
tags: [
{
name: 'GIT-HASH',
value: process.env.GITHUB_SHA,
value: process.env.GITHUB_SHA || '',
},
{
name: 'App-Name',
value: 'Permaweb-Deploy',
},
]
{
name: 'anchor',
value: new Date().toISOString(),
},
],
Comment on lines 129 to +149

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add options for custom tags in the cli here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but this is outside the scope of this pr.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to add anchor here - the github sha will be unique - and i believe we add this anchor in the ario sdk already

}
);

Expand Down
111 changes: 0 additions & 111 deletions src/turbo/index.js

This file was deleted.