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

Add keyless account support [AIP-61] #323

Merged
merged 154 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 133 commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
0c0bbcd
init commit
heliuchuan Mar 4, 2024
6121244
name ephemaccount to keypair
heliuchuan Mar 7, 2024
4038477
1.9.1-zeta.0 working
heliuchuan Mar 8, 2024
418cc08
rename expirytimestamp
heliuchuan Mar 8, 2024
bb100a2
remove console statements
heliuchuan Mar 8, 2024
f0e01bb
refactor accounts
heliuchuan Mar 11, 2024
848d2a4
Merge branch 'main' into keyless
heliuchuan Mar 11, 2024
1ccd56e
version 1.10.1-zeta.0 works locally
heliuchuan Mar 12, 2024
23c8e5c
revert example
heliuchuan Mar 12, 2024
8cee6af
rename multikeysig to multisig
heliuchuan Mar 12, 2024
1ab6404
update local->devnet for escrow example
heliuchuan Mar 13, 2024
1df46b3
turn with credentials off and add pinkas vuf
heliuchuan Mar 14, 2024
b617f9f
@1.10.0-zeta.1
heliuchuan Mar 14, 2024
e74f80a
Fixed `KeylessSignature` serialization (#331)
hardsetting Mar 19, 2024
267df99
Fixed keyless simulation (#332)
hardsetting Mar 21, 2024
747a867
extra field handling
heliuchuan Mar 26, 2024
1206130
update timeout of batch processing
heliuchuan Mar 26, 2024
025c173
1.10.0-zeta.5
heliuchuan Apr 16, 2024
e8457ba
1.10.0-zeta.6
heliuchuan Apr 16, 2024
6307194
Merge branch 'main' into keyless
heliuchuan Apr 17, 2024
5db18ed
fix build
heliuchuan Apr 22, 2024
efaf4f3
Merge branch 'main' into keyless
heliuchuan Apr 22, 2024
3fdf822
remove tweet nacl
heliuchuan Apr 22, 2024
57b6fb1
fix example
heliuchuan Apr 22, 2024
89c762c
1.13.0-zeta.1
heliuchuan Apr 26, 2024
fe6a0d9
Merge branch 'main' into keyless
heliuchuan Apr 26, 2024
0e54cc9
add accounts
heliuchuan Apr 26, 2024
27958b6
separate the signing message
heliuchuan Apr 26, 2024
f5a226c
add multisig
heliuchuan Apr 26, 2024
6d6e03a
clean up
heliuchuan Apr 26, 2024
33259cb
update transaction submission
heliuchuan Apr 26, 2024
7ceb3e6
fix account imports
heliuchuan Apr 26, 2024
b76e4cc
update singlekey sign
heliuchuan Apr 26, 2024
80a1d25
delete old accounts
heliuchuan Apr 26, 2024
29d9716
update changelog
heliuchuan Apr 26, 2024
186e15a
update
heliuchuan Apr 26, 2024
7d4944a
lint
heliuchuan Apr 26, 2024
959b4f3
fix imports
heliuchuan Apr 26, 2024
edfd438
fix the domain separator salt
heliuchuan Apr 26, 2024
878ca69
remove test.only
heliuchuan Apr 26, 2024
707be7f
fix tests
heliuchuan Apr 26, 2024
b12be78
fmt
heliuchuan Apr 26, 2024
ed6c519
Update CHANGELOG.md
heliuchuan Apr 26, 2024
8b0f205
fmt
heliuchuan Apr 27, 2024
d57c49c
Merge branch 'migrate-accounts' into keyless
heliuchuan Apr 27, 2024
feaef70
1.13.1
heliuchuan Apr 30, 2024
f893121
1.13.1-zeta.3
heliuchuan Apr 30, 2024
a8e98fb
1.13.1-zeta.5
heliuchuan Apr 30, 2024
c2e281d
Merge branch 'main' into keyless
heliuchuan Apr 30, 2024
b7a8ddc
add expiry check helper
heliuchuan May 6, 2024
2b81a99
Add event emitter
heliuchuan May 6, 2024
6ec0a7c
1.13.3-zeta.1
heliuchuan May 6, 2024
aaaeed5
1.13.3-zeta.3
heliuchuan May 10, 2024
75dbc00
address comments
heliuchuan May 13, 2024
069fc97
address more comments
heliuchuan May 13, 2024
9857790
Merge branch 'main' into migrate-accounts
heliuchuan May 13, 2024
7a441fe
fix test
heliuchuan May 13, 2024
908ef95
Merge branch 'migrate-accounts' into keyless
heliuchuan May 13, 2024
6a61852
update change log
heliuchuan May 13, 2024
84fa132
fix test
heliuchuan May 13, 2024
c79ff44
use test constant
heliuchuan May 13, 2024
877057e
remove old code
heliuchuan May 13, 2024
ded2e92
fmt
heliuchuan May 13, 2024
980661d
Merge branch 'migrate-accounts' into keyless
heliuchuan May 13, 2024
e2147b2
revert simulation changes
heliuchuan May 13, 2024
d98d076
fix import
heliuchuan May 14, 2024
276e086
Merge branch 'migrate-accounts' into keyless
heliuchuan May 14, 2024
2024b16
revert multikeysig rename
heliuchuan May 14, 2024
e4a5bf6
Update account interface
heliuchuan May 14, 2024
86cbc1a
Merge branch 'migrate-accounts' into keyless
heliuchuan May 14, 2024
becc847
add serializable class
heliuchuan May 14, 2024
05737ad
add docstrings and implement verifySignature
heliuchuan May 14, 2024
15c9f97
add test for verification
heliuchuan May 14, 2024
8c07a73
fmt
heliuchuan May 14, 2024
2132878
add test for misordering signers
heliuchuan May 15, 2024
2dffbe3
Merge branch 'migrate-accounts' into keyless
heliuchuan May 15, 2024
ab33bf8
Merge branch 'main' into keyless
heliuchuan May 15, 2024
9b634c2
update example
heliuchuan May 16, 2024
3880817
ekp docstrings
heliuchuan May 16, 2024
06c41ae
update docs
heliuchuan May 16, 2024
7a78d48
remove waitfortxn changes
heliuchuan May 16, 2024
492fcde
add docstring to ekp.generate
heliuchuan May 16, 2024
8285fd5
remove unused dep
heliuchuan May 16, 2024
316e540
remove slip 10 code
heliuchuan May 16, 2024
406fa5c
update docs
heliuchuan May 17, 2024
92ff8f7
add poseidon test
heliuchuan May 17, 2024
c331149
refactor crypto/keyless
heliuchuan May 17, 2024
13656d6
delete escrow example
heliuchuan May 17, 2024
601d9d0
reorder keyless account
heliuchuan May 17, 2024
5cf1ca7
add deserializer opt
heliuchuan May 17, 2024
97e3578
refactor keyless crypto
heliuchuan May 17, 2024
c3fa271
1.14.0-zeta.1
heliuchuan May 17, 2024
b011e89
1.14.0-zeta.2
heliuchuan May 17, 2024
8f66105
revert version
heliuchuan May 17, 2024
9d48445
Merge branch 'main' into keyless
heliuchuan May 17, 2024
b84b494
change base-64 libraries
heliuchuan May 17, 2024
90684bd
fix simulation
heliuchuan May 17, 2024
a61e4e2
update example
heliuchuan May 17, 2024
0c9902e
revert
heliuchuan May 17, 2024
57630eb
refactor errors, add expirytime to epk gen
heliuchuan May 17, 2024
d61a3a3
remove keyless error
heliuchuan May 23, 2024
7efa176
update test keyless accounts
heliuchuan May 23, 2024
18c2be0
add serialization/deserialization test
heliuchuan May 23, 2024
d6b8393
fix signing message
heliuchuan May 23, 2024
40d2714
remove turning off waitforindexer
heliuchuan May 23, 2024
109a48b
fix signing message test
heliuchuan May 23, 2024
f949e21
tidy up the example
heliuchuan May 23, 2024
7c6ec59
resolve a bunch of comments
heliuchuan May 23, 2024
8bfe4a5
resolve a bunch of comments
heliuchuan May 23, 2024
5498438
Merge branch 'main' into keyless
heliuchuan May 23, 2024
a8a2f3a
update lockfile
heliuchuan May 23, 2024
3be143f
address comments
heliuchuan May 28, 2024
2017860
address comments
heliuchuan May 28, 2024
924a73f
update balance and poseidon tests
heliuchuan May 28, 2024
ddc8ffb
address comments
heliuchuan May 28, 2024
dd4fe87
add docs
heliuchuan May 28, 2024
3370e7d
update deserializeOption doc
heliuchuan May 28, 2024
fed84ca
update serializer docs
heliuchuan May 28, 2024
af41187
updates
heliuchuan May 28, 2024
a15b143
fix g2 point
heliuchuan May 28, 2024
592c222
add poseidon test
heliuchuan May 29, 2024
abad82e
1.16.0-zeta.3
heliuchuan May 30, 2024
db25714
whitespace
heliuchuan May 30, 2024
835287f
Merge branch 'main' into keyless
heliuchuan May 30, 2024
06e99b5
add docstring
heliuchuan May 30, 2024
6fafcf5
add error handling
heliuchuan May 30, 2024
e54ddc5
add comment
heliuchuan May 30, 2024
6622ec4
elaborate on callback docs
heliuchuan May 30, 2024
cdecc97
add docs
heliuchuan May 30, 2024
88136ff
fmt
heliuchuan May 30, 2024
406b27e
address comments
heliuchuan May 30, 2024
c1410ba
Add docstrings
heliuchuan May 30, 2024
41bb648
fmt
heliuchuan May 30, 2024
824bada
update
heliuchuan May 30, 2024
3505c68
Merge branch 'main' into keyless
heliuchuan May 30, 2024
797d6b0
update changelog
heliuchuan May 30, 2024
605629a
remove async genEPK
heliuchuan May 30, 2024
4f53446
clean up
heliuchuan May 30, 2024
7f2ec01
remove jose
heliuchuan May 30, 2024
c427424
update pnpm lock
heliuchuan May 30, 2024
ade61c1
address gabis comments
heliuchuan May 31, 2024
f664f3c
Remove cryptoHashable
heliuchuan May 31, 2024
ab93d3b
rename keyless test account to sender
heliuchuan Jun 3, 2024
f3c1ea5
tweak multikey proof wait
heliuchuan Jun 3, 2024
89e2535
fmt
heliuchuan Jun 3, 2024
f081c7a
add original address lookup
heliuchuan Jun 3, 2024
19ead9f
Merge branch 'main' into keyless
heliuchuan Jun 3, 2024
e1d3a6d
add test for static constructor
heliuchuan Jun 3, 2024
d1e1f08
fmt
heliuchuan Jun 3, 2024
45be0d7
make constructor private
heliuchuan Jun 3, 2024
052ffae
remove random to fix codeql complaint
heliuchuan Jun 3, 2024
37db4e5
add more tokens
heliuchuan Jun 3, 2024
5ff7a1a
update docstring
heliuchuan Jun 3, 2024
eebff67
fmt
heliuchuan Jun 3, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to the Aptos TypeScript SDK will be captured in this file. T
- TypeTag parsing now support references, uppercase types, and more complete error handling
- Allow simple string inputs as type arguments in move scripts
- [`Fix`] Block APIs will now pull all associated transactions in the block, not just the first `100`
- Adds Keyless Account support

# 1.16.0 (2024-05-22)

Expand Down
117 changes: 117 additions & 0 deletions examples/typescript/keyless.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/* eslint-disable max-len */
/* eslint-disable no-console */

/**
* This example shows how to use the Keyless accounts on Aptos
*/

import { Account, AccountAddress, Aptos, AptosConfig, EphemeralKeyPair, Network } from "@aptos-labs/ts-sdk";
import * as readlineSync from "readline-sync";

const COIN_STORE = "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>";
const ALICE_INITIAL_BALANCE = 100_000_000;
const BOB_INITIAL_BALANCE = 100;
const TRANSFER_AMOUNT = 10_000;

/**
* Prints the balance of an account
* @param aptos
* @param name
* @param address
* @returns {Promise<*>}
*
*/
const balance = async (aptos: Aptos, name: string, address: AccountAddress) => {
type Coin = { coin: { value: string } };
const resource = await aptos.getAccountResource<Coin>({
accountAddress: address,
resourceType: COIN_STORE,
});
const amount = Number(resource.coin.value);

console.log(`${name}'s balance is: ${amount}`);
return amount;
};

const example = async () => {
heliuchuan marked this conversation as resolved.
Show resolved Hide resolved
// Setup the client
const config = new AptosConfig({ network: Network.DEVNET });
const aptos = new Aptos(config);

// Generate the ephemeral (temporary) key pair that will be used to sign transactions.
const aliceEphem = EphemeralKeyPair.generate();

console.log("\n=== Keyless Account Example ===\n");

const link = `https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&prompt=consent&response_type=code&client_id=407408718192.apps.googleusercontent.com&scope=openid&access_type=offline&service=lso&o2v=2&theme=glif&flowName=GeneralOAuthFlow&nonce=${aliceEphem.nonce}`;
console.log(`${link}\n`);

console.log("1. Open the link above");
console.log("2. Log in with your Google account");
console.log("3. Click 'Exchange authorization code for tokens");
console.log("4. Copy the 'id_token' - (toggling 'Wrap lines' option at the bottom makes this easier)\n");

function inputJwt(): string {
const jwt: string = readlineSync.question("Paste the JWT (id_token) token here and press enter: ", {
hideEchoBack: false,
});
return jwt;
}

const jwt = inputJwt();
// Derive the Keyless Account from the JWT and ephemeral key pair.
const alice = await aptos.deriveKeylessAccount({
jwt,
ephemeralKeyPair: aliceEphem,
});

console.log("=== Addresses ===\n");
console.log(`Alice's keyless account address is: ${alice.accountAddress}`);
console.log(`Alice's nonce is: ${aliceEphem.nonce}`);
console.log(`Alice's ephem pubkey is: ${aliceEphem.getPublicKey().toString()}`);

const bob = Account.generate();
console.log(`Bob's address is: ${bob.accountAddress}`);

// Fund the accounts
console.log("\n=== Funding accounts ===\n");

await aptos.fundAccount({
accountAddress: alice.accountAddress,
amount: ALICE_INITIAL_BALANCE,
});
await aptos.faucet.fundAccount({
accountAddress: bob.accountAddress,
amount: BOB_INITIAL_BALANCE,
options: { waitForIndexer: false },
});

// // Show the balances
console.log("\n=== Balances ===\n");
const aliceBalance = await balance(aptos, "Alice", alice.accountAddress);
const bobBalance = await balance(aptos, "Bob", bob.accountAddress);

// Transfer between users
const transaction = await aptos.transferCoinTransaction({
sender: alice.accountAddress,
recipient: bob.accountAddress,
amount: TRANSFER_AMOUNT,
});

const committedTxn = await aptos.signAndSubmitTransaction({ signer: alice, transaction });

await aptos.waitForTransaction({ transactionHash: committedTxn.hash });
console.log(`Committed transaction: ${committedTxn.hash}`);

console.log("\n=== Balances after transfer ===\n");
const newAliceBalance = await balance(aptos, "Alice", alice.accountAddress);
const newBobBalance = await balance(aptos, "Bob", bob.accountAddress);

// Bob should have the transfer amount
if (TRANSFER_AMOUNT !== newBobBalance - bobBalance) throw new Error("Bob's balance after transfer is incorrect");

// Alice should have the remainder minus gas
if (TRANSFER_AMOUNT >= aliceBalance - newAliceBalance) throw new Error("Alice's balance after transfer is incorrect");
};

example();
8 changes: 6 additions & 2 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@
"external_signing": "ts-node external_signing.ts",
"your_coin": "ts-node your_coin.ts",
"your_fungible_asset": "ts-node your_fungible_asset.ts",
"keyless": "ts-node keyless.ts",
"keyless_escrow": "ts-node keyless_escrow.ts",
"test": "run-s simple_transfer multi_agent_transfer simple_sponsored_transaction transfer_coin custom_client publish_package_from_filepath external_signing sign_struct publish_package_from_filepath external_signing your_coin your_fungible_asset"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@noble/curves": "^1.4.0",
"@types/readline-sync": "^1.4.8",
"dotenv": "^16.3.1",
"npm-run-all": "latest",
"superagent": "^8.1.2",
"@noble/curves": "^1.4.0"
"readline-sync": "^1.4.10",
"superagent": "^8.1.2"
},
"peerDependencies": {
"@aptos-labs/ts-sdk": "link:../.."
Expand Down
Loading
Loading