Skip to content

Commit e9e20e8

Browse files
committed
end to end tests
1 parent cfd87d0 commit e9e20e8

File tree

11 files changed

+14361
-1035
lines changed

11 files changed

+14361
-1035
lines changed

.tmp/Thirdweb API Reference.json

Lines changed: 12383 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDHOpUjE5HrGaps
3+
jIPwyPzohZe381Ou4R51Wf2bIpzn5QMVoOrTfqeFm+yqlepGocEErdL68LOpM+S0
4+
TunrdiVq9Q2FD9tBZLxyz+RDq+jbDPVZpEcVRm/GMS4WbaQERz6fL5QuUJU8hWu8
5+
ltmVRuEvwI+1cLuAn/YhtPB5H7jMDsf1bU9OO0sBcnZSsxCM0H9EVKp3GiIg6uEC
6+
bBPL8Af9C+BB0ixeLCrHeBH1c38J1LZm+XOb+89/r306DXGLYfj3dYyCkd6LlgWm
7+
868tnxYRGPJZ+y4DNg7+fdRj8FSKHWxTRAbOS6OFl8OeBkuc3xlnqmeMItbTtNFn
8+
K5yjIbPlAgMBAAECggEABahHNeDHYvqumTiAQqUicWPhxAp31N51o/VzOyWHeRpK
9+
tSGFqY3OKgAcf1eUeH79YSmidRfCskpT8z7Oa65GL7xXrvCdVEUNCOGYZMeL7DR4
10+
/xuoHRWL9P/OhDqGzsxLHfAW8B2/ryFGxustsIx7toRsUEWsPWHNdnWR4o6hC8JO
11+
1tP4B+5HC7gh5P5Mx58qSZgvSDOeqs3WgNvfvuSaAmk96CaYrDK5hhVCtfSaaAQp
12+
dB0FgmiKllHQl5rdXf3N2jPDsQPvfrpJII6/xIheBzOpWBBl63yds3Yq7uvZRTmA
13+
hOgPo1gBPJ1/8dXVegAKiYYh2nEXXqjP4LqJ2oJPXQKBgQDxFA7ODZAa2CAKVSrH
14+
ubyB++PgpmYhiIk0bplmo2i3OKVxKebRyA58IpU2adHo4KcE5UcNp4awCaQTNdLf
15+
8XPl6h2tcLseDL5EXZkOnifk4n0OMJpmb4jZ6bbfHrmM7V1huM/VS40HzVe92eH7
16+
+TS0roXzgD3osFzB3D3SKdKIZwKBgQDTj2jXYRctIrHN6oWzuELo9QOVE5IuNP5Q
17+
LbOBK8hB6K54zmSRo4rOTzc15Jbx1BaEwvkExzFxmpSS86ie9uW0aN+ofQy+NApC
18+
ejR6atsfFVcsayrbrTBqCACKphYmy0biysubYGdQqfrj4VXKOn+JyWuFKZ1sulxA
19+
TWHP1Qoh0wKBgQCBB/BInv/DLmwvu5fTIHlhxPUZt1Ywmoh9NLkMM2gHsNzz7a5q
20+
F76Q+F2OqyK7lwot152pFEJFlFNqKMO+MtiKdTz/KLguBDoOE16pcUL/Aa5XWvI4
21+
43eG0s2bLDG52Q3DEQzEJ9TLGT/eEHEg0ShBkKuHQdtg4Iw1AnFgPBw//wKBgQCD
22+
vFQzcXDGGUmQiI2y6HU5rIALj0FCZptJf/u73nB3ohUqgpKbIbQoXalqdKoNcdyH
23+
1QTNFeBS9ke37eO9AM7udTN4Lk4GDk+pL4GIDQvfIiHDNgRdAE4aaFs1+s/mXkQI
24+
qvD4EqKi1wW0ardKEv0h5nt+UviFINKa89SJXwZNIwKBgBl165tu0uMTPj+nxyTa
25+
Fn1W46hN/zf/3Znwux3zdlUfqTi0pMLWXPNFRmHkgii/SuVyGrua3csmhWJQQ8c7
26+
7BRsdmvu8IcTGeD+HHqhgwklppITrMRwluxg/aqEGZ+Zm4T9Qhn7ayB25OsS5YlR
27+
Iino9D1dG0jaltViLWf3t2pM
28+
-----END PRIVATE KEY-----
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIEOTCCAqGgAwIBAgIQE/NiYvurcd65CnbAD0mk7zANBgkqhkiG9w0BAQsFADBt
3+
MR4wHAYDVQQKExVta2NlcnQgZG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A7R
19+
UtG2dqwbRQqC6z/rTlzIsHGL2MAL2dvW+Cc7hN3WshuqTbHw4CncnwpxipK2Vv30
20+
nNuwZuUt71qWwbGVfOqMQzoSzjWcqcK4omXdUvbIFAvWJetQKB1CQYx1GKJmLm7K
21+
XL47gGuTUIWOeACNBp9Wuxal0+q/zZolNi7ZCEaRw42tTGiVW/mPGovXHu8CDitY
22+
3E1zJt92SkrCziiA6eWflNin8q3IVmW1SEJwVYI6QT9NcFVaKObJ3E9t5d2JUPEr
23+
lh6EoZM7Ayvh9SBwYrn0xP58F1wkl6VHugZLYqbx0GYJnVN3EA67AB0f6skZLRyL
24+
S6PuUlXqnBT1rJw+Ozh9SaKdQ7jl0508ZK5Z6M8=
25+
-----END CERTIFICATE-----

packages/vault-sdk/package.json

Lines changed: 71 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,73 @@
11
{
2-
"author": "thirdweb eng <[email protected]>",
3-
"bugs": {
4-
"url": "https://github.com/thirdweb-dev/js/issues"
5-
},
6-
"dependencies": {
7-
"@noble/ciphers": "^1.2.1",
8-
"@noble/curves": "1.8.2",
9-
"@noble/hashes": "1.7.2",
10-
"@solana/addresses": "^3.0.0",
11-
"@solana/keys": "^3.0.0",
12-
"@solana/transactions": "^3.0.0",
13-
"@solana/rpc": "^3.0.0",
14-
"abitype": "1.0.8",
15-
"jose": "6.0.11"
16-
},
17-
"devDependencies": {
18-
"@biomejs/biome": "2.0.6",
19-
"tsx": "^4.0.0",
20-
"rimraf": "6.0.1"
21-
},
22-
"engines": {
23-
"node": ">=18"
24-
},
25-
"exports": {
26-
".": {
27-
"types": "./dist/types/exports/thirdweb.d.ts",
28-
"import": "./dist/esm/exports/thirdweb.js",
29-
"default": "./dist/cjs/exports/thirdweb.js"
30-
},
31-
"./package.json": "./package.json"
32-
},
33-
"files": [
34-
"dist/*",
35-
"src/*"
36-
],
37-
"license": "Apache-2.0",
38-
"main": "./dist/cjs/exports/thirdweb.js",
39-
"module": "./dist/esm/exports/thirdweb.js",
40-
"name": "@thirdweb-dev/vault-sdk",
41-
"peerDependencies": {
42-
"typescript": ">=5.0.4"
43-
},
44-
"peerDependenciesMeta": {
45-
"typescript": {
46-
"optional": true
47-
}
48-
},
49-
"repository": {
50-
"type": "git",
51-
"url": "git+https://github.com/thirdweb-dev/js.git#main"
52-
},
53-
"scripts": {
54-
"build": "pnpm clean && pnpm build:cjs && pnpm build:esm && pnpm build:types",
55-
"build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./dist/cjs --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./dist/cjs/package.json",
56-
"build:esm": "tsc --project ./tsconfig.build.json --module es2020 --outDir ./dist/esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./dist/esm/package.json",
57-
"build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
58-
"clean": "rimraf dist",
59-
"test:solana": "tsx test-solana.ts",
60-
"dev": "tsc --project ./tsconfig.build.json --module es2020 --outDir ./dist/esm --watch",
61-
"fix": "biome check ./src --fix",
62-
"format": "biome format ./src --write",
63-
"lint": "biome check ./src"
64-
},
65-
"type": "module",
66-
"types": "./dist/types/exports/thirdweb.d.ts",
67-
"typings": "./dist/types/exports/thirdweb.d.ts",
68-
"version": "0.0.3"
2+
"author": "thirdweb eng <[email protected]>",
3+
"bugs": {
4+
"url": "https://github.com/thirdweb-dev/js/issues"
5+
},
6+
"dependencies": {
7+
"@noble/ciphers": "^1.2.1",
8+
"@noble/curves": "1.8.2",
9+
"@noble/hashes": "1.7.2",
10+
"@solana/addresses": "^3.0.0",
11+
"@solana/keys": "^3.0.0",
12+
"@solana/rpc": "^3.0.0",
13+
"@solana/transactions": "^3.0.0",
14+
"abitype": "1.0.8",
15+
"@solana/kit": "^4.0.0",
16+
"jose": "6.0.11"
17+
},
18+
"devDependencies": {
19+
"@biomejs/biome": "2.0.6",
20+
"@solana-program/system": "^0.8.1",
21+
"bs58": "^6.0.0",
22+
"rimraf": "6.0.1",
23+
"tsx": "^4.0.0",
24+
"vitest": "3.2.4"
25+
},
26+
"engines": {
27+
"node": ">=18"
28+
},
29+
"exports": {
30+
".": {
31+
"types": "./dist/types/exports/thirdweb.d.ts",
32+
"import": "./dist/esm/exports/thirdweb.js",
33+
"default": "./dist/cjs/exports/thirdweb.js"
34+
},
35+
"./package.json": "./package.json"
36+
},
37+
"files": [
38+
"dist/*",
39+
"src/*"
40+
],
41+
"license": "Apache-2.0",
42+
"main": "./dist/cjs/exports/thirdweb.js",
43+
"module": "./dist/esm/exports/thirdweb.js",
44+
"name": "@thirdweb-dev/vault-sdk",
45+
"peerDependencies": {
46+
"typescript": ">=5.0.4"
47+
},
48+
"peerDependenciesMeta": {
49+
"typescript": {
50+
"optional": true
51+
}
52+
},
53+
"repository": {
54+
"type": "git",
55+
"url": "git+https://github.com/thirdweb-dev/js.git#main"
56+
},
57+
"scripts": {
58+
"build": "pnpm clean && pnpm build:cjs && pnpm build:esm && pnpm build:types",
59+
"build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./dist/cjs --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./dist/cjs/package.json",
60+
"build:esm": "tsc --project ./tsconfig.build.json --module es2020 --outDir ./dist/esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./dist/esm/package.json",
61+
"build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
62+
"clean": "rimraf dist",
63+
"test": "vitest",
64+
"dev": "tsc --project ./tsconfig.build.json --module es2020 --outDir ./dist/esm --watch",
65+
"fix": "biome check ./src --fix",
66+
"format": "biome format ./src --write",
67+
"lint": "biome check ./src"
68+
},
69+
"type": "module",
70+
"types": "./dist/types/exports/thirdweb.d.ts",
71+
"typings": "./dist/types/exports/thirdweb.d.ts",
72+
"version": "0.0.3"
6973
}

packages/vault-sdk/src/sdk.ts

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,16 @@ import { x25519 } from "@noble/curves/ed25519";
33
import { hkdf } from "@noble/hashes/hkdf";
44
import { sha256 } from "@noble/hashes/sha256";
55
import { bytesToHex, hexToBytes, randomBytes } from "@noble/hashes/utils";
6-
import type { TypedData } from "abitype";
7-
import * as jose from "jose";
8-
9-
// Base58 encoding for Solana public keys
10-
const BASE58_ALPHABET =
11-
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
12-
13-
function base58Encode(bytes: number[] | Uint8Array): string {
14-
const byteArray = Array.isArray(bytes) ? new Uint8Array(bytes) : bytes;
156

16-
if (byteArray.length === 0) return "";
17-
18-
// Convert to big integer
19-
let num = 0n;
20-
for (const byte of byteArray) {
21-
num = num * 256n + BigInt(byte);
22-
}
23-
24-
// Convert to base58
25-
let result = "";
26-
while (num > 0n) {
27-
const remainder = Number(num % 58n);
28-
result = BASE58_ALPHABET[remainder] + result;
29-
num = num / 58n;
30-
}
31-
32-
// Add leading zeros
33-
for (const byte of byteArray) {
34-
if (byte === 0) {
35-
result = BASE58_ALPHABET[0] + result;
36-
} else {
37-
break;
38-
}
39-
}
40-
41-
return result;
42-
}
43-
44-
// Helper function to process Solana account data
45-
function _processSolanaAccountData(accountData: any): any {
46-
if (!accountData) return accountData;
47-
48-
// If we have a pubkey byte array, convert it to base58 string
49-
if (accountData.pubkey && Array.isArray(accountData.pubkey)) {
50-
accountData.publicKey = base58Encode(accountData.pubkey);
51-
accountData.address = accountData.publicKey; // Use the same value for address
52-
}
53-
54-
return accountData;
55-
}
7+
import {
8+
address,
9+
getBase58Encoder,
10+
getTransactionDecoder,
11+
getTransactionEncoder,
12+
} from "@solana/kit";
5613

14+
import type { TypedData } from "abitype";
15+
import * as jose from "jose";
5716
import type {
5817
CheckedSignTypedDataPayload,
5918
CreateAccessTokenPayload,
@@ -540,6 +499,42 @@ export function signSolanaTransaction({
540499
});
541500
}
542501

502+
/**
503+
* Reconstruct a signed solana transaction from the vault signature using @solana/kit
504+
*/
505+
export function reconstructSolanaSignedTransaction(
506+
base64Transaction: string,
507+
base58Signature: string,
508+
signerPubkey: string,
509+
): Uint8Array {
510+
// Decode the base64 transaction into bytes
511+
const base64TransactionBytes = new Uint8Array(
512+
Buffer.from(base64Transaction, "base64"),
513+
);
514+
// Decode the transaction to get its structure
515+
const transactionDecoder = getTransactionDecoder();
516+
const transaction = transactionDecoder.decode(base64TransactionBytes);
517+
518+
// Decode the base58 signature to bytes
519+
const base58Encoder = getBase58Encoder();
520+
const signatureBytes = base58Encoder.encode(base58Signature);
521+
522+
// Add the signature to the transaction
523+
const signedTransaction = {
524+
...transaction,
525+
signatures: {
526+
...transaction.signatures,
527+
[address(signerPubkey)]: signatureBytes,
528+
},
529+
};
530+
531+
// Re-encode the signed transaction
532+
const transactionEncoder = getTransactionEncoder();
533+
const signedTransactionBytes = transactionEncoder.encode(signedTransaction);
534+
535+
return new Uint8Array(signedTransactionBytes);
536+
}
537+
543538
export function signSolanaMessage({
544539
client,
545540
request: options,

0 commit comments

Comments
 (0)