@1shotapi/ows-signer-utils 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/README.md +162 -0
- package/dist/eip1193/approval-types.d.ts +22 -0
- package/dist/eip1193/approval-types.d.ts.map +1 -0
- package/dist/eip1193/approval-types.js +2 -0
- package/dist/eip1193/approval-types.js.map +1 -0
- package/dist/eip1193/sign-helper.d.ts +64 -0
- package/dist/eip1193/sign-helper.d.ts.map +1 -0
- package/dist/eip1193/sign-helper.js +87 -0
- package/dist/eip1193/sign-helper.js.map +1 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +2 -0
- package/dist/errors.js.map +1 -0
- package/dist/evm/marshal.d.ts +8 -0
- package/dist/evm/marshal.d.ts.map +1 -0
- package/dist/evm/marshal.js +44 -0
- package/dist/evm/marshal.js.map +1 -0
- package/dist/evm/namespace.d.ts +18 -0
- package/dist/evm/namespace.d.ts.map +1 -0
- package/dist/evm/namespace.js +43 -0
- package/dist/evm/namespace.js.map +1 -0
- package/dist/evm/to-viem-account.d.ts +4 -0
- package/dist/evm/to-viem-account.d.ts.map +1 -0
- package/dist/evm/to-viem-account.js +26 -0
- package/dist/evm/to-viem-account.js.map +1 -0
- package/dist/iframe.d.ts +36 -0
- package/dist/iframe.d.ts.map +1 -0
- package/dist/iframe.js +170 -0
- package/dist/iframe.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/owssigner.d.ts +55 -0
- package/dist/owssigner.d.ts.map +1 -0
- package/dist/owssigner.js +227 -0
- package/dist/owssigner.js.map +1 -0
- package/dist/rpc/client.d.ts +26 -0
- package/dist/rpc/client.d.ts.map +1 -0
- package/dist/rpc/client.js +153 -0
- package/dist/rpc/client.js.map +1 -0
- package/dist/rpc/parse-public-keys.d.ts +5 -0
- package/dist/rpc/parse-public-keys.d.ts.map +1 -0
- package/dist/rpc/parse-public-keys.js +59 -0
- package/dist/rpc/parse-public-keys.js.map +1 -0
- package/dist/rpc/types.d.ts +2 -0
- package/dist/rpc/types.d.ts.map +1 -0
- package/dist/rpc/types.js +2 -0
- package/dist/rpc/types.js.map +1 -0
- package/dist/solana/address.d.ts +4 -0
- package/dist/solana/address.d.ts.map +1 -0
- package/dist/solana/address.js +7 -0
- package/dist/solana/address.js.map +1 -0
- package/dist/solana/namespace.d.ts +11 -0
- package/dist/solana/namespace.d.ts.map +1 -0
- package/dist/solana/namespace.js +19 -0
- package/dist/solana/namespace.js.map +1 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# @1shotapi/ows-signer-utils
|
|
2
|
+
|
|
3
|
+
Typed, browser-only SDK for **Branding Layer** authors: embed the OWS Signing Layer iframe, speak the OWS v1 `postMessage` protocol, and expose `OWSSigner` with passkey/recovery helpers plus a Viem-aligned `signer.evm` namespace.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @1shotapi/ows-signer-utils viem
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`viem` is a **peer dependency** (^2.x). This package uses viem for EIP-191/712/transaction/7702 hashing, serialization, and types — not as a wallet client.
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { OWSSigner, toViemLocalAccount } from "@1shotapi/ows-signer-utils";
|
|
17
|
+
|
|
18
|
+
const container = document.getElementById("signer-slot")!;
|
|
19
|
+
const signer = await OWSSigner.create(
|
|
20
|
+
container,
|
|
21
|
+
"https://your-signer.example/signer.html",
|
|
22
|
+
{ credentialId: optionalExistingId },
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
await signer.createCredential("my-wallet", { rpName: "MyBrand" });
|
|
26
|
+
|
|
27
|
+
const address = await signer.evm.getAccountAddress();
|
|
28
|
+
const sig = await signer.evm.signMessage({ message: "hello" });
|
|
29
|
+
const typedSig = await signer.evm.signTypedData({
|
|
30
|
+
domain: { name: "App", version: "1", chainId: 1, verifyingContract: "0x…" },
|
|
31
|
+
types: { … },
|
|
32
|
+
primaryType: "Mail",
|
|
33
|
+
message: { … },
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Optional: viem LocalAccount for smart-account kits
|
|
37
|
+
const account = await toViemLocalAccount(signer);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Architecture
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
Host Layer → Branding Layer → Signing Layer
|
|
44
|
+
↑
|
|
45
|
+
@1shotapi/ows-signer-utils
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
This package runs in the **Branding Layer**. It must not be used from the host page directly — the Signing Layer requires the branding iframe for correct WebAuthn / iframe nesting.
|
|
49
|
+
|
|
50
|
+
Outbound RPC: `iframe.contentWindow.postMessage(request, signerOrigin)`
|
|
51
|
+
Inbound events: validate `event.origin === signerOrigin` and `event.source === iframe.contentWindow`.
|
|
52
|
+
|
|
53
|
+
## Iframe requirements
|
|
54
|
+
|
|
55
|
+
- Parent page must be a [secure context](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts) (HTTPS or localhost).
|
|
56
|
+
- The iframe is created with `allow="publickey-credentials-get *"` for passkey ceremonies.
|
|
57
|
+
- Do **not** add a restrictive `sandbox` that blocks WebAuthn.
|
|
58
|
+
- Default iframe size is hidden (`0×0`); pass `{ hidden: false }` to show it.
|
|
59
|
+
|
|
60
|
+
### Showing the signer over UI (passphrase / recovery)
|
|
61
|
+
|
|
62
|
+
Do **not** reparent the signer iframe into a dialog — that can reload the iframe document and drop in-flight RPCs. Use:
|
|
63
|
+
|
|
64
|
+
| Helper | Purpose |
|
|
65
|
+
|--------|---------|
|
|
66
|
+
| `overlaySignerIframe(iframe, slot, options?)` | Visible overlay: position the iframe's home container over a slot (e.g. backup dialog). Returns a restore function. |
|
|
67
|
+
| `prepareSignerIframeForWebAuthn(iframe)` | Invisible 1×1 focus layer for passkey ceremonies (used internally by `OWSSigner`). |
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { overlaySignerIframe } from "@1shotapi/ows-signer-utils";
|
|
71
|
+
|
|
72
|
+
const restore = overlaySignerIframe(iframe, signerSlot, {
|
|
73
|
+
homeContainer: document.getElementById("signer-container")!,
|
|
74
|
+
});
|
|
75
|
+
try {
|
|
76
|
+
await signer.createRecoveryData(/* … */);
|
|
77
|
+
} finally {
|
|
78
|
+
restore();
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### EIP-1193 signing (`SignHelper`)
|
|
83
|
+
|
|
84
|
+
Headless `personal_sign` / `eth_signTypedData*` orchestration (display → consent → ensureReady → sign). Does not register handlers — the branding app owns order:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { SignHelper } from "@1shotapi/ows-signer-utils";
|
|
88
|
+
|
|
89
|
+
const signHelper = new SignHelper(signer, wallet, {
|
|
90
|
+
ensureReady,
|
|
91
|
+
requestPersonalSignApproval,
|
|
92
|
+
requestSignTypedDataApproval,
|
|
93
|
+
});
|
|
94
|
+
for (const [method, handler] of Object.entries(signHelper.handlers)) {
|
|
95
|
+
wallet.registerEip1193(method, handler);
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Consent UI stays app-owned (see `examples/general-wallet` approval dialog).
|
|
100
|
+
|
|
101
|
+
## API
|
|
102
|
+
|
|
103
|
+
### `OWSSigner.create(container, signerUrl, options?)`
|
|
104
|
+
|
|
105
|
+
| Option | Description |
|
|
106
|
+
|--------|-------------|
|
|
107
|
+
| `credentialId` | Existing WebAuthn credential id |
|
|
108
|
+
| `hidden` | Hide iframe (default `true`) |
|
|
109
|
+
| `rpcTimeoutMs` | RPC timeout (default 120s) |
|
|
110
|
+
|
|
111
|
+
### Root methods (Signing Layer passthrough)
|
|
112
|
+
|
|
113
|
+
| Method | Description |
|
|
114
|
+
|--------|-------------|
|
|
115
|
+
| `getVersion()` | Signer API/version info |
|
|
116
|
+
| `createCredential(name, options?)` | Register passkey; options include `rpName`, `userDisplayName`, `userId` |
|
|
117
|
+
| `signDigest(digest, scheme?, credentialId?)` | Sign a 32-byte `0x` digest |
|
|
118
|
+
| `getPublicKey(params?)` | Derive keys; optional `challenge` for `ChallengeSigned` |
|
|
119
|
+
| `createRecoveryData(...)` | Encrypt recovery blob |
|
|
120
|
+
| `recoverKey(...)` | Decrypt recovery blob into session |
|
|
121
|
+
| `revealPrivateKey(credentialId?)` | Signer UI to reveal key |
|
|
122
|
+
| `clearRecoverySession()` | End recovery session |
|
|
123
|
+
| `encryptAES256(plaintexts, credentialId?)` | Batch AES-256-GCM seal (`ows-aes1:`) |
|
|
124
|
+
| `decryptAES256(ciphertexts, credentialId?)` | Batch AES-256-GCM unseal |
|
|
125
|
+
|
|
126
|
+
### `signer.evm`
|
|
127
|
+
|
|
128
|
+
| Method | Description |
|
|
129
|
+
|--------|-------------|
|
|
130
|
+
| `getAccountAddress()` | Ethereum address from secp256k1 public key |
|
|
131
|
+
| `signMessage({ message })` | EIP-191 personal sign |
|
|
132
|
+
| `signTypedData(typedData)` | EIP-712 |
|
|
133
|
+
| `signTransaction(transaction)` | Returns signed serialized tx hex |
|
|
134
|
+
| `signAuthorization(authorization)` | EIP-7702 authorization |
|
|
135
|
+
|
|
136
|
+
All EVM methods accept optional `{ credentialId }` per call.
|
|
137
|
+
|
|
138
|
+
### `signer.solana`
|
|
139
|
+
|
|
140
|
+
| Method | Description |
|
|
141
|
+
|--------|-------------|
|
|
142
|
+
| `getAccountAddress()` | Solana address (base58 ed25519 public key) |
|
|
143
|
+
|
|
144
|
+
Accepts optional `{ credentialId }` per call.
|
|
145
|
+
|
|
146
|
+
### Errors
|
|
147
|
+
|
|
148
|
+
- `OwsNotAllowedError` — user cancelled or policy blocked
|
|
149
|
+
- `OwsInvalidRequestError` — bad params
|
|
150
|
+
- `OwsTimeoutError` — RPC timeout
|
|
151
|
+
|
|
152
|
+
## Related packages
|
|
153
|
+
|
|
154
|
+
| Package | Role |
|
|
155
|
+
|---------|------|
|
|
156
|
+
| `@1shotapi/ows-signer` | Plain JS Signing Layer |
|
|
157
|
+
| `@1shotapi/ows-wallet-utils` | Host Layer ↔ Branding Layer messaging |
|
|
158
|
+
| `@1shotapi/ows-provider` | EIP-1193 provider for Host Layer apps |
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
MIT
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { EVMAccountAddress } from "@1shotapi/ows-types";
|
|
2
|
+
/** EIP-191 personal_sign consent payload for branding UI. */
|
|
3
|
+
export type PersonalSignApprovalRequest = {
|
|
4
|
+
message: string;
|
|
5
|
+
address: EVMAccountAddress;
|
|
6
|
+
};
|
|
7
|
+
/** EIP-712 typed data payload (`eth_signTypedData` / `_v3` / `_v4`). */
|
|
8
|
+
export type SignTypedDataPayload = {
|
|
9
|
+
types: Record<string, Array<{
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
}>>;
|
|
13
|
+
primaryType: string;
|
|
14
|
+
domain: Record<string, unknown>;
|
|
15
|
+
message: Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
/** EIP-712 typed-data consent payload for branding UI. */
|
|
18
|
+
export type SignTypedDataApprovalRequest = {
|
|
19
|
+
address: EVMAccountAddress;
|
|
20
|
+
typedData: SignTypedDataPayload;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=approval-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval-types.d.ts","sourceRoot":"","sources":["../../src/eip1193/approval-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,6DAA6D;AAC7D,MAAM,MAAM,2BAA2B,GAAG;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,iBAAiB,CAAC;CAC5B,CAAC;AAEF,wEAAwE;AACxE,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;IAC7D,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAAC;AAEF,0DAA0D;AAC1D,MAAM,MAAM,4BAA4B,GAAG;IACzC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,SAAS,EAAE,oBAAoB,CAAC;CACjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval-types.js","sourceRoot":"","sources":["../../src/eip1193/approval-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type RequestDisplayParams } from "@1shotapi/ows-types";
|
|
2
|
+
import type { TypedDataDefinition } from "viem";
|
|
3
|
+
import type { PersonalSignApprovalRequest, SignTypedDataApprovalRequest, SignTypedDataPayload } from "./approval-types.js";
|
|
4
|
+
/** EIP-1193 handler shape (matches `OWSWallet.registerEip1193`). */
|
|
5
|
+
export type Eip1193Handler = (params: unknown[]) => Promise<unknown>;
|
|
6
|
+
export type SignHelperDisplaySession = {
|
|
7
|
+
hide(): Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
/** Wallet surface used to show the branding iframe during consent / signing. */
|
|
10
|
+
export type SignHelperWallet = {
|
|
11
|
+
requestDisplay(params: RequestDisplayParams): Promise<SignHelperDisplaySession>;
|
|
12
|
+
};
|
|
13
|
+
/** Minimal EVM signing surface (`OWSSigner.evm` subset). */
|
|
14
|
+
export type SignHelperSigner = {
|
|
15
|
+
evm: {
|
|
16
|
+
signMessage(args: {
|
|
17
|
+
message: string;
|
|
18
|
+
}): Promise<string>;
|
|
19
|
+
signTypedData(typedData: TypedDataDefinition, options?: {
|
|
20
|
+
credentialId?: string;
|
|
21
|
+
}): Promise<string>;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export type SignHelperDisplaySize = {
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
};
|
|
28
|
+
export type SignHelperOptions = {
|
|
29
|
+
/** Run before signing (e.g. passkey unlock / onboarding). */
|
|
30
|
+
ensureReady?: () => Promise<void>;
|
|
31
|
+
/** Consent UI for EIP-191 personal_sign. */
|
|
32
|
+
requestPersonalSignApproval: (request: PersonalSignApprovalRequest) => Promise<boolean>;
|
|
33
|
+
/** Consent UI for EIP-712 typed data. */
|
|
34
|
+
requestSignTypedDataApproval: (request: SignTypedDataApprovalRequest) => Promise<boolean>;
|
|
35
|
+
/** Flyout size for personal_sign (default 448×360). */
|
|
36
|
+
personalSignDisplaySize?: SignHelperDisplaySize;
|
|
37
|
+
/** Flyout size for typed data (default 448×520). */
|
|
38
|
+
typedDataDisplaySize?: SignHelperDisplaySize;
|
|
39
|
+
};
|
|
40
|
+
export type Eip1193SignHandlers = {
|
|
41
|
+
personal_sign: Eip1193Handler;
|
|
42
|
+
eth_signTypedData: Eip1193Handler;
|
|
43
|
+
eth_signTypedData_v3: Eip1193Handler;
|
|
44
|
+
eth_signTypedData_v4: Eip1193Handler;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Headless EIP-1193 personal_sign / typed-data wiring: display → consent →
|
|
48
|
+
* ensureReady → sign. Does **not** register handlers — the branding app calls
|
|
49
|
+
* `wallet.registerEip1193` in the order it wants.
|
|
50
|
+
*
|
|
51
|
+
* Transaction signing is intentionally omitted (broadcast / monitoring TBD).
|
|
52
|
+
*/
|
|
53
|
+
export declare class SignHelper {
|
|
54
|
+
private readonly signer;
|
|
55
|
+
private readonly wallet;
|
|
56
|
+
private readonly options;
|
|
57
|
+
readonly handlers: Eip1193SignHandlers;
|
|
58
|
+
constructor(signer: SignHelperSigner, wallet: SignHelperWallet, options: SignHelperOptions);
|
|
59
|
+
private handlePersonalSign;
|
|
60
|
+
private handleTypedData;
|
|
61
|
+
private withDisplay;
|
|
62
|
+
}
|
|
63
|
+
export declare function parseTypedData(value: SignTypedDataPayload | string): SignTypedDataPayload;
|
|
64
|
+
//# sourceMappingURL=sign-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign-helper.d.ts","sourceRoot":"","sources":["../../src/eip1193/sign-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,KAAK,EACV,2BAA2B,EAC3B,4BAA4B,EAC5B,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAE7B,oEAAoE;AACpE,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAErE,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB,CAAC;AAEF,gFAAgF;AAChF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,cAAc,CACZ,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,wBAAwB,CAAC,CAAC;CACtC,CAAC;AAEF,4DAA4D;AAC5D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE;QACH,WAAW,CAAC,IAAI,EAAE;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QACxD,aAAa,CACX,SAAS,EAAE,mBAAmB,EAC9B,OAAO,CAAC,EAAE;YAAE,YAAY,CAAC,EAAE,MAAM,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{ EVMAccountAddress, OwsUserRejectedError, } from "@1shotapi/ows-types";
|
|
2
|
+
const DEFAULT_PERSONAL_SIGN_SIZE = {
|
|
3
|
+
width: 448,
|
|
4
|
+
height: 360,
|
|
5
|
+
};
|
|
6
|
+
const DEFAULT_TYPED_DATA_SIZE = {
|
|
7
|
+
width: 448,
|
|
8
|
+
height: 520,
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Headless EIP-1193 personal_sign / typed-data wiring: display → consent →
|
|
12
|
+
* ensureReady → sign. Does **not** register handlers — the branding app calls
|
|
13
|
+
* `wallet.registerEip1193` in the order it wants.
|
|
14
|
+
*
|
|
15
|
+
* Transaction signing is intentionally omitted (broadcast / monitoring TBD).
|
|
16
|
+
*/
|
|
17
|
+
export class SignHelper {
|
|
18
|
+
signer;
|
|
19
|
+
wallet;
|
|
20
|
+
options;
|
|
21
|
+
handlers;
|
|
22
|
+
constructor(signer, wallet, options) {
|
|
23
|
+
this.signer = signer;
|
|
24
|
+
this.wallet = wallet;
|
|
25
|
+
this.options = options;
|
|
26
|
+
const typedData = (params) => this.handleTypedData(params);
|
|
27
|
+
this.handlers = {
|
|
28
|
+
personal_sign: (params) => this.handlePersonalSign(params),
|
|
29
|
+
eth_signTypedData: typedData,
|
|
30
|
+
eth_signTypedData_v3: typedData,
|
|
31
|
+
eth_signTypedData_v4: typedData,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async handlePersonalSign(params) {
|
|
35
|
+
const [message, addressParam] = params;
|
|
36
|
+
const address = EVMAccountAddress(addressParam);
|
|
37
|
+
const size = this.options.personalSignDisplaySize ?? DEFAULT_PERSONAL_SIGN_SIZE;
|
|
38
|
+
return this.withDisplay(size, async () => {
|
|
39
|
+
const approved = await this.options.requestPersonalSignApproval({
|
|
40
|
+
message,
|
|
41
|
+
address,
|
|
42
|
+
});
|
|
43
|
+
if (!approved) {
|
|
44
|
+
throw new OwsUserRejectedError("User rejected the signing request");
|
|
45
|
+
}
|
|
46
|
+
if (this.options.ensureReady) {
|
|
47
|
+
await this.options.ensureReady();
|
|
48
|
+
}
|
|
49
|
+
return this.signer.evm.signMessage({ message });
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async handleTypedData(params) {
|
|
53
|
+
const [addressParam, typedDataParam] = params;
|
|
54
|
+
const address = EVMAccountAddress(addressParam);
|
|
55
|
+
const typedData = parseTypedData(typedDataParam);
|
|
56
|
+
const size = this.options.typedDataDisplaySize ?? DEFAULT_TYPED_DATA_SIZE;
|
|
57
|
+
return this.withDisplay(size, async () => {
|
|
58
|
+
const approved = await this.options.requestSignTypedDataApproval({
|
|
59
|
+
address,
|
|
60
|
+
typedData,
|
|
61
|
+
});
|
|
62
|
+
if (!approved) {
|
|
63
|
+
throw new OwsUserRejectedError("User rejected the signing request");
|
|
64
|
+
}
|
|
65
|
+
if (this.options.ensureReady) {
|
|
66
|
+
await this.options.ensureReady();
|
|
67
|
+
}
|
|
68
|
+
return this.signer.evm.signTypedData(typedData);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async withDisplay(size, run) {
|
|
72
|
+
const display = await this.wallet.requestDisplay(size);
|
|
73
|
+
try {
|
|
74
|
+
return await run();
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
await display.hide();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export function parseTypedData(value) {
|
|
82
|
+
if (typeof value === "string") {
|
|
83
|
+
return JSON.parse(value);
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=sign-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign-helper.js","sourceRoot":"","sources":["../../src/eip1193/sign-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,oBAAoB,GAErB,MAAM,qBAAqB,CAAC;AA8D7B,MAAM,0BAA0B,GAA0B;IACxD,KAAK,EAAE,GAA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C,IAAI,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAC5B,KAAoC;IAEpC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAyB,CAAC;IACnD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,kBAAkB,EAClB,eAAe,GAChB,MAAM,qBAAqB,CAAC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,kBAAkB,EAClB,eAAe,GAChB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AuthorizationRequest, Hex, SignableMessage, SignedAuthorization, TransactionSerializable, TypedDataDefinition } from "viem";
|
|
2
|
+
export declare function digestForMessage(message: SignableMessage): Hex;
|
|
3
|
+
export declare function digestForTypedData(typedData: TypedDataDefinition): Hex;
|
|
4
|
+
export declare function digestForTransaction(transaction: TransactionSerializable): Hex;
|
|
5
|
+
export declare function digestForAuthorization(authorization: AuthorizationRequest): Hex;
|
|
6
|
+
export declare function serializeSignedTransaction(transaction: TransactionSerializable, signature: Hex): Hex;
|
|
7
|
+
export declare function signedAuthorizationFromSignature(authorization: AuthorizationRequest, signature: Hex): SignedAuthorization;
|
|
8
|
+
//# sourceMappingURL=marshal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marshal.d.ts","sourceRoot":"","sources":["../../src/evm/marshal.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,oBAAoB,EACpB,GAAG,EACH,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,MAAM,CAAC;AAEd,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,GAAG,CAE9D;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,mBAAmB,GAC7B,GAAG,CAEL;AAED,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,uBAAuB,GACnC,GAAG,CAGL;AAED,wBAAgB,sBAAsB,CACpC,aAAa,EAAE,oBAAoB,GAClC,GAAG,CAEL;AAED,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,uBAAuB,EACpC,SAAS,EAAE,GAAG,GACb,GAAG,CAEL;AAED,wBAAgB,gCAAgC,CAC9C,aAAa,EAAE,oBAAoB,EACnC,SAAS,EAAE,GAAG,GACb,mBAAmB,CA0BrB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { hashMessage, hashTypedData, keccak256, parseSignature, serializeTransaction, } from "viem";
|
|
2
|
+
import { hashAuthorization } from "viem/utils";
|
|
3
|
+
export function digestForMessage(message) {
|
|
4
|
+
return hashMessage(message);
|
|
5
|
+
}
|
|
6
|
+
export function digestForTypedData(typedData) {
|
|
7
|
+
return hashTypedData(typedData);
|
|
8
|
+
}
|
|
9
|
+
export function digestForTransaction(transaction) {
|
|
10
|
+
const serialized = serializeTransaction(transaction);
|
|
11
|
+
return keccak256(serialized);
|
|
12
|
+
}
|
|
13
|
+
export function digestForAuthorization(authorization) {
|
|
14
|
+
return hashAuthorization(authorization);
|
|
15
|
+
}
|
|
16
|
+
export function serializeSignedTransaction(transaction, signature) {
|
|
17
|
+
return serializeTransaction(transaction, parseSignature(signature));
|
|
18
|
+
}
|
|
19
|
+
export function signedAuthorizationFromSignature(authorization, signature) {
|
|
20
|
+
const parsed = parseSignature(signature);
|
|
21
|
+
const address = authorization.address ?? authorization.contractAddress;
|
|
22
|
+
if (!address) {
|
|
23
|
+
throw new Error("Authorization requires address or contractAddress");
|
|
24
|
+
}
|
|
25
|
+
if ("v" in parsed && parsed.v !== undefined) {
|
|
26
|
+
return {
|
|
27
|
+
address,
|
|
28
|
+
chainId: authorization.chainId,
|
|
29
|
+
nonce: authorization.nonce,
|
|
30
|
+
r: parsed.r,
|
|
31
|
+
s: parsed.s,
|
|
32
|
+
v: parsed.v,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
address,
|
|
37
|
+
chainId: authorization.chainId,
|
|
38
|
+
nonce: authorization.nonce,
|
|
39
|
+
r: parsed.r,
|
|
40
|
+
s: parsed.s,
|
|
41
|
+
yParity: parsed.yParity,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=marshal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marshal.js","sourceRoot":"","sources":["../../src/evm/marshal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,aAAa,EACb,SAAS,EACT,cAAc,EACd,oBAAoB,GACrB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAU/C,MAAM,UAAU,gBAAgB,CAAC,OAAwB;IACvD,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,SAA8B;IAE9B,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,WAAoC;IAEpC,MAAM,UAAU,GAAG,oBAAoB,CAAC,WAAW,CAAC,CAAC;IACrD,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,aAAmC;IAEnC,OAAO,iBAAiB,CAAC,aAAa,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,WAAoC,EACpC,SAAc;IAEd,OAAO,oBAAoB,CAAC,WAAW,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC9C,aAAmC,EACnC,SAAc;IAEd,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IACzC,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,aAAa,CAAC,eAAe,CAAC;IACvE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAED,IAAI,GAAG,IAAI,MAAM,IAAI,MAAM,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;QAC5C,OAAO;YACL,OAAO;YACP,OAAO,EAAE,aAAa,CAAC,OAAO;YAC9B,KAAK,EAAE,aAAa,CAAC,KAAK;YAC1B,CAAC,EAAE,MAAM,CAAC,CAAC;YACX,CAAC,EAAE,MAAM,CAAC,CAAC;YACX,CAAC,EAAE,MAAM,CAAC,CAAC;SACZ,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO;QACP,OAAO,EAAE,aAAa,CAAC,OAAO;QAC9B,KAAK,EAAE,aAAa,CAAC,KAAK;QAC1B,CAAC,EAAE,MAAM,CAAC,CAAC;QACX,CAAC,EAAE,MAAM,CAAC,CAAC;QACX,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EVMAccountAddress } from "@1shotapi/ows-types";
|
|
2
|
+
import type { AuthorizationRequest, Hex, SignableMessage, SignedAuthorization, TransactionSerializable, TypedDataDefinition } from "viem";
|
|
3
|
+
import type { OWSSigner } from "../owssigner.js";
|
|
4
|
+
export type EvmCallOptions = {
|
|
5
|
+
credentialId?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class EvmSigner {
|
|
8
|
+
private readonly signer;
|
|
9
|
+
constructor(signer: OWSSigner);
|
|
10
|
+
getAccountAddress(options?: EvmCallOptions): Promise<EVMAccountAddress>;
|
|
11
|
+
signMessage(args: {
|
|
12
|
+
message: SignableMessage;
|
|
13
|
+
} & EvmCallOptions): Promise<Hex>;
|
|
14
|
+
signTypedData<const typedData extends TypedDataDefinition>(typedData: typedData, options?: EvmCallOptions): Promise<Hex>;
|
|
15
|
+
signTransaction(transaction: TransactionSerializable, options?: EvmCallOptions): Promise<Hex>;
|
|
16
|
+
signAuthorization(authorization: AuthorizationRequest, options?: EvmCallOptions): Promise<SignedAuthorization>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=namespace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../src/evm/namespace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EACV,oBAAoB,EACpB,GAAG,EACH,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,MAAM,CAAC;AAEd,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAYjD,MAAM,MAAM,cAAc,GAAG;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,qBAAa,SAAS;IACR,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,SAAS;IAExC,iBAAiB,CACrB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,iBAAiB,CAAC;IAevB,WAAW,CACf,IAAI,EAAE;QAAE,OAAO,EAAE,eAAe,CAAA;KAAE,GAAG,cAAc,GAClD,OAAO,CAAC,GAAG,CAAC;IAWT,aAAa,CAAC,KAAK,CAAC,SAAS,SAAS,mBAAmB,EAC7D,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,GAAG,CAAC;IAUT,eAAe,CACnB,WAAW,EAAE,uBAAuB,EACpC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,GAAG,CAAC;IAUT,iBAAiB,CACrB,aAAa,EAAE,oBAAoB,EACnC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,mBAAmB,CAAC;CAShC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { EVMAccountAddress } from "@1shotapi/ows-types";
|
|
2
|
+
import { publicKeyToAddress } from "viem/utils";
|
|
3
|
+
import { digestForAuthorization, digestForMessage, digestForTransaction, digestForTypedData, serializeSignedTransaction, signedAuthorizationFromSignature, } from "./marshal.js";
|
|
4
|
+
const EVM_SIGN_SCHEME = "secp256k1-ecdsa-recoverable";
|
|
5
|
+
export class EvmSigner {
|
|
6
|
+
signer;
|
|
7
|
+
constructor(signer) {
|
|
8
|
+
this.signer = signer;
|
|
9
|
+
}
|
|
10
|
+
async getAccountAddress(options) {
|
|
11
|
+
const cached = this.signer.getCachedAddress();
|
|
12
|
+
if (cached)
|
|
13
|
+
return cached;
|
|
14
|
+
const publicKey = await this.signer.getPublicKey({
|
|
15
|
+
credentialId: options?.credentialId ?? this.signer.getCredentialId(),
|
|
16
|
+
});
|
|
17
|
+
const address = EVMAccountAddress(publicKeyToAddress(publicKey.secp256k1PublicKey));
|
|
18
|
+
this.signer.setCachedAddress(address);
|
|
19
|
+
return address;
|
|
20
|
+
}
|
|
21
|
+
async signMessage(args) {
|
|
22
|
+
const { message, credentialId } = args;
|
|
23
|
+
const digest = digestForMessage(message);
|
|
24
|
+
const result = await this.signer.signDigest(digest, EVM_SIGN_SCHEME, credentialId ?? this.signer.getCredentialId());
|
|
25
|
+
return result.signature;
|
|
26
|
+
}
|
|
27
|
+
async signTypedData(typedData, options) {
|
|
28
|
+
const digest = digestForTypedData(typedData);
|
|
29
|
+
const result = await this.signer.signDigest(digest, EVM_SIGN_SCHEME, options?.credentialId ?? this.signer.getCredentialId());
|
|
30
|
+
return result.signature;
|
|
31
|
+
}
|
|
32
|
+
async signTransaction(transaction, options) {
|
|
33
|
+
const digest = digestForTransaction(transaction);
|
|
34
|
+
const result = await this.signer.signDigest(digest, EVM_SIGN_SCHEME, options?.credentialId ?? this.signer.getCredentialId());
|
|
35
|
+
return serializeSignedTransaction(transaction, result.signature);
|
|
36
|
+
}
|
|
37
|
+
async signAuthorization(authorization, options) {
|
|
38
|
+
const digest = digestForAuthorization(authorization);
|
|
39
|
+
const result = await this.signer.signDigest(digest, EVM_SIGN_SCHEME, options?.credentialId ?? this.signer.getCredentialId());
|
|
40
|
+
return signedAuthorizationFromSignature(authorization, result.signature);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=namespace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespace.js","sourceRoot":"","sources":["../../src/evm/namespace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AASxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,0BAA0B,EAC1B,gCAAgC,GACjC,MAAM,cAAc,CAAC;AAEtB,MAAM,eAAe,GAAG,6BAAsC,CAAC;AAM/D,MAAM,OAAO,SAAS;IACS;IAA7B,YAA6B,MAAiB;QAAjB,WAAM,GAAN,MAAM,CAAW;IAAG,CAAC;IAElD,KAAK,CAAC,iBAAiB,CACrB,OAAwB;QAExB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAC9C,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;QAE1B,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;YAC/C,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE;SACrE,CAAC,CAAC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,aAAmC,EACnC,OAAwB;QAExB,MAAM,MAAM,GAAG,sBAAsB,CAAC,aAAa,CAAC,CAAC;QACrD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CACzC,MAAM,EACN,eAAe,EACf,OAAO,EAAE,YAAY,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CACvD,CAAC;QACF,OAAO,gCAAgC,CAAC,aAAa,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;IAC3E,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-viem-account.d.ts","sourceRoot":"","sources":["../../src/evm/to-viem-account.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,YAAY,CAAC,CA0BvB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export async function toViemLocalAccount(signer) {
|
|
2
|
+
const address = await signer.evm.getAccountAddress();
|
|
3
|
+
const publicKeyResult = await signer.getPublicKey({
|
|
4
|
+
credentialId: signer.getCredentialId(),
|
|
5
|
+
});
|
|
6
|
+
const account = {
|
|
7
|
+
address: address,
|
|
8
|
+
type: "local",
|
|
9
|
+
source: "owsSigner",
|
|
10
|
+
publicKey: publicKeyResult.secp256k1PublicKey,
|
|
11
|
+
async signMessage({ message }) {
|
|
12
|
+
return signer.evm.signMessage({ message });
|
|
13
|
+
},
|
|
14
|
+
async signTransaction(transaction) {
|
|
15
|
+
return signer.evm.signTransaction(transaction);
|
|
16
|
+
},
|
|
17
|
+
async signTypedData(typedData) {
|
|
18
|
+
return signer.evm.signTypedData(typedData);
|
|
19
|
+
},
|
|
20
|
+
async signAuthorization(authorization) {
|
|
21
|
+
return signer.evm.signAuthorization(authorization);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
return account;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=to-viem-account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-viem-account.js","sourceRoot":"","sources":["../../src/evm/to-viem-account.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAiB;IAEjB,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC;IACrD,MAAM,eAAe,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC;QAChD,YAAY,EAAE,MAAM,CAAC,eAAe,EAAE;KACvC,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG;QACd,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,WAAW;QACnB,SAAS,EAAE,eAAe,CAAC,kBAAkB;QAC7C,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE;YAC3B,OAAO,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAC7C,CAAC;QACD,KAAK,CAAC,eAAe,CAAC,WAAW;YAC/B,OAAO,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QACjD,CAAC;QACD,KAAK,CAAC,aAAa,CAAC,SAAS;YAC3B,OAAO,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,SAAgC,CAAC,CAAC;QACpE,CAAC;QACD,KAAK,CAAC,iBAAiB,CAAC,aAAa;YACnC,OAAO,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;QACrD,CAAC;KACqB,CAAC;IAEzB,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/iframe.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type CreateSignerIframeOptions = {
|
|
2
|
+
hidden?: boolean;
|
|
3
|
+
};
|
|
4
|
+
export type OverlaySignerIframeOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Element that currently holds the iframe in the DOM (usually the branding
|
|
7
|
+
* `#signer-container`). Defaults to `iframe.parentElement`.
|
|
8
|
+
*/
|
|
9
|
+
homeContainer?: HTMLElement;
|
|
10
|
+
/** Stacking order for the overlaid home container and iframe (default `"10001"`). */
|
|
11
|
+
zIndex?: string;
|
|
12
|
+
/** Home-container background while overlaid (default `"Canvas"`). */
|
|
13
|
+
background?: string;
|
|
14
|
+
/** Home-container border radius while overlaid (default `"6px"`). */
|
|
15
|
+
borderRadius?: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Make the nested custody signer iframe visible/focusable for WebAuthn.
|
|
19
|
+
* Uses a 1×1 invisible fixed layer — distinct from {@link overlaySignerIframe},
|
|
20
|
+
* which shows the signer UI (e.g. passphrase) over a dialog slot.
|
|
21
|
+
*
|
|
22
|
+
* Call synchronously immediately before a signer RPC that triggers passkey UI.
|
|
23
|
+
*/
|
|
24
|
+
export declare function prepareSignerIframeForWebAuthn(iframe: HTMLIFrameElement): () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Visually place the signer iframe over `slot` without moving it in the DOM.
|
|
27
|
+
* Reparenting can reload the iframe document and drop pending signer RPCs.
|
|
28
|
+
*
|
|
29
|
+
* Positions the iframe's home container (fixed) to match `slot.getBoundingClientRect()`,
|
|
30
|
+
* then stretches the iframe to fill that container. Call the returned function to
|
|
31
|
+
* restore prior inline styles.
|
|
32
|
+
*/
|
|
33
|
+
export declare function overlaySignerIframe(iframe: HTMLIFrameElement, slot: HTMLElement, options?: OverlaySignerIframeOptions): () => void;
|
|
34
|
+
export declare function createSignerIframe(container: HTMLElement, signerUrl: string, options?: CreateSignerIframeOptions): Promise<HTMLIFrameElement>;
|
|
35
|
+
export declare function getSignerOrigin(signerUrl: string): string;
|
|
36
|
+
//# sourceMappingURL=iframe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iframe.d.ts","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,aAAa,CAAC,EAAE,WAAW,CAAC;IAC5B,qFAAqF;IACrF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AA4DF;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,iBAAiB,GACxB,MAAM,IAAI,CA0CZ;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAE,WAAW,EACjB,OAAO,GAAE,0BAA+B,GACvC,MAAM,IAAI,CAoDZ;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,EACtB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,iBAAiB,CAAC,CAoC5B;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEzD"}
|