@wallets-e2e/freighter 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +121 -2
- package/fixtures/wallet.ts +41 -0
- package/lib/fixtures/wallet.d.ts +15 -0
- package/lib/fixtures/wallet.d.ts.map +1 -0
- package/lib/fixtures/wallet.js +36 -0
- package/lib/fixtures/wallet.js.map +1 -0
- package/lib/src/extension.d.ts +27 -0
- package/lib/src/extension.d.ts.map +1 -0
- package/lib/src/extension.js +82 -0
- package/lib/src/extension.js.map +1 -0
- package/lib/src/index.d.ts +40 -0
- package/lib/src/index.d.ts.map +1 -0
- package/lib/src/index.js +56 -0
- package/lib/src/index.js.map +1 -0
- package/lib/src/networks.d.ts +14 -0
- package/lib/src/networks.d.ts.map +1 -0
- package/lib/src/networks.js +16 -0
- package/lib/src/networks.js.map +1 -0
- package/lib/src/onboarding.d.ts +40 -0
- package/lib/src/onboarding.d.ts.map +1 -0
- package/lib/src/onboarding.js +137 -0
- package/lib/src/onboarding.js.map +1 -0
- package/lib/src/prompts.d.ts +16 -0
- package/lib/src/prompts.d.ts.map +1 -0
- package/lib/src/prompts.js +41 -0
- package/lib/src/prompts.js.map +1 -0
- package/lib/src/selectors.d.ts +56 -0
- package/lib/src/selectors.d.ts.map +1 -0
- package/lib/src/selectors.js +50 -0
- package/lib/src/selectors.js.map +1 -0
- package/lib/src/test.d.ts +26 -0
- package/lib/src/test.d.ts.map +1 -0
- package/lib/src/test.js +36 -0
- package/lib/src/test.js.map +1 -0
- package/lib/src/utils.d.ts +14 -0
- package/lib/src/utils.d.ts.map +1 -0
- package/lib/src/utils.js +29 -0
- package/lib/src/utils.js.map +1 -0
- package/package.json +71 -3
- package/scripts/extension.mjs +111 -0
- package/scripts/prepare-extension.mjs +37 -0
- package/src/extension.ts +91 -0
- package/src/index.ts +103 -0
- package/src/networks.ts +26 -0
- package/src/onboarding.ts +144 -0
- package/src/prompts.ts +61 -0
- package/src/selectors.ts +54 -0
- package/src/test.ts +64 -0
- package/src/utils.ts +32 -0
package/src/test.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PlaywrightTestArgs,
|
|
3
|
+
PlaywrightTestOptions,
|
|
4
|
+
PlaywrightWorkerArgs,
|
|
5
|
+
PlaywrightWorkerOptions,
|
|
6
|
+
TestType,
|
|
7
|
+
} from '@playwright/test';
|
|
8
|
+
import { createExtensionTest, type CreateExtensionTestOptions, type ExtensionFixtures, type ExtraExtension } from '@wallets-e2e/core';
|
|
9
|
+
import {
|
|
10
|
+
ensureFreighterExtension,
|
|
11
|
+
freighterExtensionPath,
|
|
12
|
+
FREIGHTER_PREPARE_COMMAND,
|
|
13
|
+
FREIGHTER_VERSION,
|
|
14
|
+
} from './extension.js';
|
|
15
|
+
|
|
16
|
+
type AnyTestArgs = PlaywrightTestArgs & PlaywrightTestOptions;
|
|
17
|
+
type AnyWorkerArgs = PlaywrightWorkerArgs & PlaywrightWorkerOptions;
|
|
18
|
+
|
|
19
|
+
export interface CreateFreighterTestOptions<
|
|
20
|
+
TBase extends TestType<AnyTestArgs, AnyWorkerArgs> = TestType<AnyTestArgs, AnyWorkerArgs>,
|
|
21
|
+
> extends Omit<CreateExtensionTestOptions<TBase>, 'extensionPath' | 'prepareExtension'> {
|
|
22
|
+
/** An unpacked Freighter build of your own. Defaults to the pinned one this package ships with. */
|
|
23
|
+
extensionPath?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The Playwright `test` for Freighter, with the extension already wired up: the packaged build is
|
|
28
|
+
* located, and downloaded on first use if an install skipped its `postinstall`.
|
|
29
|
+
*
|
|
30
|
+
* Consumers therefore need no extension path, no download script and no `.wallet-extensions`
|
|
31
|
+
* directory of their own — only their own artifact and profile preferences, which this forwards to
|
|
32
|
+
* `createExtensionTest` untouched.
|
|
33
|
+
*/
|
|
34
|
+
export function createFreighterTest<
|
|
35
|
+
TArgs extends AnyTestArgs = AnyTestArgs,
|
|
36
|
+
TWorkerArgs extends AnyWorkerArgs = AnyWorkerArgs,
|
|
37
|
+
>(
|
|
38
|
+
options: CreateFreighterTestOptions<TestType<TArgs, TWorkerArgs>> = {},
|
|
39
|
+
): TestType<TArgs & ExtensionFixtures, TWorkerArgs> {
|
|
40
|
+
const extensionPath = options.extensionPath ?? freighterExtensionPath();
|
|
41
|
+
return createExtensionTest<TArgs, TWorkerArgs>({
|
|
42
|
+
profilePrefix: 'wallets-e2e-freighter',
|
|
43
|
+
extensionName: `Freighter ${FREIGHTER_VERSION}`,
|
|
44
|
+
buildCommand: FREIGHTER_PREPARE_COMMAND,
|
|
45
|
+
...options,
|
|
46
|
+
extensionPath,
|
|
47
|
+
prepareExtension: () => ensureFreighterExtension(extensionPath),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Freighter as a second wallet beside another one: pass the result as `extraExtensions` of that
|
|
53
|
+
* wallet's test, e.g. `createMetamaskTest({ extraExtensions: [freighterExtraExtension()] })`. A
|
|
54
|
+
* dapp that signs on an EVM chain with MetaMask and on Stellar with Freighter gets both in one
|
|
55
|
+
* browser; `freighterDriver` finds its own extension whatever else is loaded.
|
|
56
|
+
*/
|
|
57
|
+
export function freighterExtraExtension(extensionPath: string = freighterExtensionPath()): ExtraExtension {
|
|
58
|
+
return {
|
|
59
|
+
extensionPath,
|
|
60
|
+
extensionName: `Freighter ${FREIGHTER_VERSION}`,
|
|
61
|
+
buildCommand: FREIGHTER_PREPARE_COMMAND,
|
|
62
|
+
prepareExtension: () => ensureFreighterExtension(extensionPath),
|
|
63
|
+
};
|
|
64
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// No runtime imports: `node --test` runs this file straight from source.
|
|
2
|
+
|
|
3
|
+
/** The extension's single page; every screen is a hash route of it. */
|
|
4
|
+
export const INDEX_PAGE = 'index.html';
|
|
5
|
+
|
|
6
|
+
/** A Stellar account id: `G` and 55 base32 characters. */
|
|
7
|
+
export const STELLAR_ACCOUNT = /^G[A-Z2-7]{55}$/;
|
|
8
|
+
|
|
9
|
+
/** The URL of one of the extension's screens. */
|
|
10
|
+
export function extensionUrl(extensionId: string, route = ''): string {
|
|
11
|
+
return `chrome-extension://${extensionId}/${INDEX_PAGE}${route}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Whether `url` is the extension's prompt for `route`. A prompt's URL is the route followed by `?`
|
|
16
|
+
* and the request, base64-encoded: `…/index.html#/sign-transaction?eyJ…`.
|
|
17
|
+
*/
|
|
18
|
+
export function isPromptUrl(url: string, extensionId: string, route: string): boolean {
|
|
19
|
+
const prefix = extensionUrl(extensionId, route);
|
|
20
|
+
if (!url.startsWith(prefix)) return false;
|
|
21
|
+
const rest = url.slice(prefix.length);
|
|
22
|
+
return rest === '' || rest.startsWith('?') || rest.startsWith('/');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** A recovery phrase as its words; throws on anything but 12 or 24 of them, without echoing the phrase. */
|
|
26
|
+
export function phraseWords(seedPhrase: string): string[] {
|
|
27
|
+
const words = seedPhrase.trim().split(/\s+/).filter(Boolean);
|
|
28
|
+
if (words.length !== 12 && words.length !== 24) {
|
|
29
|
+
throw new Error(`[wallets/freighter] The recovery phrase must be 12 or 24 words; got ${words.length}.`);
|
|
30
|
+
}
|
|
31
|
+
return words;
|
|
32
|
+
}
|