Skip to content

Commit cf5497c

Browse files
committed
prettier changes
1 parent 2a41fa5 commit cf5497c

File tree

2 files changed

+60
-60
lines changed

2 files changed

+60
-60
lines changed

examples/with-iota/src/index.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import * as dotenv from 'dotenv';
2-
import * as path from 'path';
3-
import { IotaClient, getFullnodeUrl } from '@iota/iota-sdk/client';
4-
import { Transaction } from '@iota/iota-sdk/transactions';
5-
import { Ed25519PublicKey } from '@iota/iota-sdk/keypairs/ed25519';
6-
import { messageWithIntent } from '@iota/iota-sdk/cryptography';
7-
import { Turnkey } from '@turnkey/sdk-server';
8-
import { blake2b } from '@noble/hashes/blake2b';
9-
import { bytesToHex } from '@noble/hashes/utils';
10-
11-
dotenv.config({ path: path.resolve(process.cwd(), '.env.local') });
1+
import * as dotenv from "dotenv";
2+
import * as path from "path";
3+
import { IotaClient, getFullnodeUrl } from "@iota/iota-sdk/client";
4+
import { Transaction } from "@iota/iota-sdk/transactions";
5+
import { Ed25519PublicKey } from "@iota/iota-sdk/keypairs/ed25519";
6+
import { messageWithIntent } from "@iota/iota-sdk/cryptography";
7+
import { Turnkey } from "@turnkey/sdk-server";
8+
import { blake2b } from "@noble/hashes/blake2b";
9+
import { bytesToHex } from "@noble/hashes/utils";
10+
11+
dotenv.config({ path: path.resolve(process.cwd(), ".env.local") });
1212

1313
function toSerializedSignature({
1414
signature,
@@ -20,12 +20,12 @@ function toSerializedSignature({
2020
const scheme = new Uint8Array([0x00]); // ED25519 flag
2121
const pubKeyBytes = pubKey.toRawBytes();
2222
const serialized = new Uint8Array(
23-
scheme.length + signature.length + pubKeyBytes.length
23+
scheme.length + signature.length + pubKeyBytes.length,
2424
);
2525
serialized.set(scheme, 0);
2626
serialized.set(signature, scheme.length);
2727
serialized.set(pubKeyBytes, scheme.length + signature.length);
28-
return Buffer.from(serialized).toString('base64');
28+
return Buffer.from(serialized).toString("base64");
2929
}
3030

3131
async function main() {
@@ -42,35 +42,35 @@ async function main() {
4242
// *** ENVIRONMENT CHECKING *** //
4343

4444
if (IOTA_ADDRESS === undefined || IOTA_PUBLIC_KEY === undefined) {
45-
throw new Error('IOTA_ADDRESS or IOTA_PUBLIC_KEY not set in .env.local');
45+
throw new Error("IOTA_ADDRESS or IOTA_PUBLIC_KEY not set in .env.local");
4646
}
4747

48-
const publicKey = new Ed25519PublicKey(Buffer.from(IOTA_PUBLIC_KEY!, 'hex'));
48+
const publicKey = new Ed25519PublicKey(Buffer.from(IOTA_PUBLIC_KEY!, "hex"));
4949
if (publicKey.toIotaAddress() !== IOTA_ADDRESS) {
50-
throw new Error('IOTA_PUBLIC_KEY does not match IOTA_ADDRESS');
50+
throw new Error("IOTA_PUBLIC_KEY does not match IOTA_ADDRESS");
5151
}
5252

5353
// sending to the same address
5454
const recipient = IOTA_ADDRESS;
5555
const amount = 1_000_000n; // 0.001 IOTA
5656

5757
const turnkeyClient = new Turnkey({
58-
apiBaseUrl: 'https://api.turnkey.com',
58+
apiBaseUrl: "https://api.turnkey.com",
5959
apiPrivateKey: API_PRIVATE_KEY!,
6060
apiPublicKey: API_PUBLIC_KEY!,
6161
defaultOrganizationId: ORGANIZATION_ID!,
6262
});
6363

6464
// *** TRANSACTION BUILDING *** //
6565

66-
const provider = new IotaClient({ url: getFullnodeUrl('testnet') });
66+
const provider = new IotaClient({ url: getFullnodeUrl("testnet") });
6767

6868
// fetch the user's IOTA coin objects
6969
const coins = await provider.getCoins({
7070
owner: IOTA_ADDRESS!,
71-
coinType: '0x2::iota::IOTA',
71+
coinType: "0x2::iota::IOTA",
7272
});
73-
if (!coins.data.length) throw new Error('No IOTA coins');
73+
if (!coins.data.length) throw new Error("No IOTA coins");
7474

7575
const tx = new Transaction();
7676
tx.setSender(IOTA_ADDRESS!);
@@ -83,37 +83,37 @@ async function main() {
8383
digest: coins.data[0]!.digest,
8484
},
8585
]); // separate intended send amount from gas payment
86-
const coin = tx.splitCoins(tx.gas, [tx.pure('u64', amount)]);
86+
const coin = tx.splitCoins(tx.gas, [tx.pure("u64", amount)]);
8787
tx.transferObjects([coin], tx.pure.address(recipient));
8888

8989
const txBytes = await tx.build();
9090

91-
const intentMsg = messageWithIntent('TransactionData', txBytes);
91+
const intentMsg = messageWithIntent("TransactionData", txBytes);
9292
const digest = blake2b(intentMsg, { dkLen: 32 });
9393

9494
const { r, s } = await turnkeyClient.apiClient().signRawPayload({
9595
signWith: IOTA_ADDRESS!,
9696
payload: bytesToHex(digest),
97-
encoding: 'PAYLOAD_ENCODING_HEXADECIMAL',
98-
hashFunction: 'HASH_FUNCTION_NOT_APPLICABLE',
97+
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
98+
hashFunction: "HASH_FUNCTION_NOT_APPLICABLE",
9999
});
100100

101-
const signature = Buffer.from(r + s, 'hex');
101+
const signature = Buffer.from(r + s, "hex");
102102
const serialized = toSerializedSignature({ signature, pubKey: publicKey });
103103

104104
// *** EXECUTION *** //
105105

106106
const result = await provider.executeTransactionBlock({
107-
transactionBlock: Buffer.from(txBytes).toString('base64'),
107+
transactionBlock: Buffer.from(txBytes).toString("base64"),
108108
signature: serialized,
109-
requestType: 'WaitForEffectsCert',
109+
requestType: "WaitForEffectsCert",
110110
options: { showEffects: true },
111111
});
112112

113-
console.log('Transaction digest:', result.digest);
113+
console.log("Transaction digest:", result.digest);
114114
}
115115

116116
main().catch((err) => {
117-
console.error('Error:', err);
117+
console.error("Error:", err);
118118
process.exit(1);
119-
});
119+
});

examples/with-sui/src/index.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import * as dotenv from 'dotenv';
2-
import * as path from 'path';
3-
import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
4-
import { Transaction } from '@mysten/sui/transactions';
5-
import { Ed25519PublicKey } from '@mysten/sui/keypairs/ed25519';
6-
import { messageWithIntent } from '@mysten/sui/cryptography';
7-
import { Turnkey } from '@turnkey/sdk-server';
8-
import { blake2b } from '@noble/hashes/blake2b';
9-
import { bytesToHex } from '@noble/hashes/utils';
10-
11-
dotenv.config({ path: path.resolve(process.cwd(), '.env.local') });
1+
import * as dotenv from "dotenv";
2+
import * as path from "path";
3+
import { SuiClient, getFullnodeUrl } from "@mysten/sui/client";
4+
import { Transaction } from "@mysten/sui/transactions";
5+
import { Ed25519PublicKey } from "@mysten/sui/keypairs/ed25519";
6+
import { messageWithIntent } from "@mysten/sui/cryptography";
7+
import { Turnkey } from "@turnkey/sdk-server";
8+
import { blake2b } from "@noble/hashes/blake2b";
9+
import { bytesToHex } from "@noble/hashes/utils";
10+
11+
dotenv.config({ path: path.resolve(process.cwd(), ".env.local") });
1212

1313
function toSerializedSignature({
1414
signature,
@@ -20,12 +20,12 @@ function toSerializedSignature({
2020
const scheme = new Uint8Array([0x00]); // ED25519 flag
2121
const pubKeyBytes = pubKey.toRawBytes();
2222
const serialized = new Uint8Array(
23-
scheme.length + signature.length + pubKeyBytes.length
23+
scheme.length + signature.length + pubKeyBytes.length,
2424
);
2525
serialized.set(scheme, 0);
2626
serialized.set(signature, scheme.length);
2727
serialized.set(pubKeyBytes, scheme.length + signature.length);
28-
return Buffer.from(serialized).toString('base64');
28+
return Buffer.from(serialized).toString("base64");
2929
}
3030

3131
async function main() {
@@ -40,35 +40,35 @@ async function main() {
4040
} = process.env;
4141

4242
if (SUI_ADDRESS === undefined || SUI_PUBLIC_KEY === undefined) {
43-
throw new Error('SUI_ADDRESS or SUI_PUBLIC_KEY not set in .env.local');
43+
throw new Error("SUI_ADDRESS or SUI_PUBLIC_KEY not set in .env.local");
4444
}
4545

46-
const publicKey = new Ed25519PublicKey(Buffer.from(SUI_PUBLIC_KEY!, 'hex'));
46+
const publicKey = new Ed25519PublicKey(Buffer.from(SUI_PUBLIC_KEY!, "hex"));
4747
if (publicKey.toSuiAddress() !== SUI_ADDRESS) {
48-
throw new Error('SUI_PUBLIC_KEY does not match SUI_ADDRESS');
48+
throw new Error("SUI_PUBLIC_KEY does not match SUI_ADDRESS");
4949
}
5050

5151
// sending to the same address
5252
const recipient = SUI_ADDRESS;
5353
const amount = 1_000_000n; // 0.001 SUI
5454

5555
const turnkeyClient = new Turnkey({
56-
apiBaseUrl: 'https://api.turnkey.com',
56+
apiBaseUrl: "https://api.turnkey.com",
5757
apiPrivateKey: API_PRIVATE_KEY!,
5858
apiPublicKey: API_PUBLIC_KEY!,
5959
defaultOrganizationId: ORGANIZATION_ID!,
6060
});
6161

6262
// *** TRANSACTION BUILDING *** //
6363

64-
const provider = new SuiClient({ url: getFullnodeUrl('testnet') });
64+
const provider = new SuiClient({ url: getFullnodeUrl("testnet") });
6565

6666
// fetch the user's SUI coin objects
6767
const coins = await provider.getCoins({
6868
owner: SUI_ADDRESS!,
69-
coinType: '0x2::sui::SUI',
69+
coinType: "0x2::sui::SUI",
7070
});
71-
if (!coins.data.length) throw new Error('No SUI coins');
71+
if (!coins.data.length) throw new Error("No SUI coins");
7272

7373
const tx = new Transaction();
7474
tx.setSender(SUI_ADDRESS!);
@@ -81,37 +81,37 @@ async function main() {
8181
digest: coins.data[0]!.digest,
8282
},
8383
]); // separate intended send amount from gas payment
84-
const coin = tx.splitCoins(tx.gas, [tx.pure('u64', amount)]);
84+
const coin = tx.splitCoins(tx.gas, [tx.pure("u64", amount)]);
8585
tx.transferObjects([coin], tx.pure.address(recipient));
8686

8787
const txBytes = await tx.build();
8888

89-
const intentMsg = messageWithIntent('TransactionData', txBytes);
89+
const intentMsg = messageWithIntent("TransactionData", txBytes);
9090
const digest = blake2b(intentMsg, { dkLen: 32 });
9191

9292
const { r, s } = await turnkeyClient.apiClient().signRawPayload({
9393
signWith: SUI_ADDRESS!,
9494
payload: bytesToHex(digest),
95-
encoding: 'PAYLOAD_ENCODING_HEXADECIMAL',
96-
hashFunction: 'HASH_FUNCTION_NOT_APPLICABLE',
95+
encoding: "PAYLOAD_ENCODING_HEXADECIMAL",
96+
hashFunction: "HASH_FUNCTION_NOT_APPLICABLE",
9797
});
9898

99-
const signature = Buffer.from(r + s, 'hex');
99+
const signature = Buffer.from(r + s, "hex");
100100
const serialized = toSerializedSignature({ signature, pubKey: publicKey });
101101

102102
// *** EXECUTION *** //
103103

104104
const result = await provider.executeTransactionBlock({
105-
transactionBlock: Buffer.from(txBytes).toString('base64'),
105+
transactionBlock: Buffer.from(txBytes).toString("base64"),
106106
signature: serialized,
107-
requestType: 'WaitForEffectsCert',
107+
requestType: "WaitForEffectsCert",
108108
options: { showEffects: true },
109109
});
110110

111-
console.log('Transaction digest:', result.digest);
111+
console.log("Transaction digest:", result.digest);
112112
}
113113

114114
main().catch((err) => {
115-
console.error('Error:', err);
115+
console.error("Error:", err);
116116
process.exit(1);
117-
});
117+
});

0 commit comments

Comments
 (0)