@etherplay/connect-core 0.3.0 → 0.5.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.
@@ -0,0 +1,169 @@
1
+ import { type AllowlistLookup, type DelegationTarget } from './permissions.js';
2
+ /**
3
+ * WHO MAY ASK FOR AN ACCOUNT THAT IS NOT THEIRS.
4
+ *
5
+ * A request is CROSS-ORIGIN when the window that opened the wallet is not the origin being signed
6
+ * for: `evil.example` opening the popup with `signingOrigin=https://game.example` is asking for the
7
+ * signer `game.example` derives, which is the whole of that account's authority there.
8
+ *
9
+ * The answer is NO, unless the origin whose account is at stake has said otherwise. That default is
10
+ * affordable because there is now a way to do this properly: a delegation contract authorises MANY
11
+ * delegates, so a third-party site can bring its OWN origin signer and have the user register it
12
+ * onchain. That costs a transaction, which is why the consent list below still exists, but it means
13
+ * refusing is no longer refusing the use case.
14
+ *
15
+ * WHAT THIS IS NOT. It is not a guarantee that no page can obtain a cross-origin signer. In the
16
+ * external-wallet path the app asks the user's own wallet to sign the origin message with no host
17
+ * in the loop, and nothing here is consulted; the message text in the wallet's dialog is the only
18
+ * gate there. What this does guarantee is that THIS HOST will not hand over an account for an
19
+ * origin that did not agree to it.
20
+ *
21
+ * WHAT THE GUARANTEE RESTS ON, AND IT IS NOT IN THIS FILE. `windowOrigin` is a value the opener
22
+ * writes; nothing here authenticates it, so a page can claim to be `https://game.example` and be
23
+ * answered `same-origin`. What makes the lie worthless is DELIVERY, not this decision: the host
24
+ * posts the result with `targetOrigin: windowOrigin` and only ever adopts an opener whose
25
+ * `event.origin` matches, so a page that lies is instructing the browser to hand the account to a
26
+ * window it is not. A claimed origin is therefore safe to decide on and unsafe to act on any other
27
+ * way, and any future path that returns something to the app WITHOUT that origin lock breaks this
28
+ * module's guarantee without touching this module.
29
+ */
30
+ /**
31
+ * What one signing origin accepts.
32
+ *
33
+ * `'*'` means "anyone may ASK", which is emphatically not "anyone is trusted": there is still a
34
+ * human prompt, and it is a stronger one, because the host knows nothing about who is asking. An
35
+ * array is the meaningful form: named requesters, matched exactly.
36
+ */
37
+ export type CrossOriginConsent = '*' | string[];
38
+ /**
39
+ * How a host looks up that consent.
40
+ *
41
+ * ASYNCHRONOUS ON PURPOSE, while every implementation is a hardcoded table. The table is expected
42
+ * to become something fetched (a document served by the signing origin itself is self-attesting in
43
+ * the way a central list is not), and an async boundary drawn later is a rewrite of every call
44
+ * site, at the exact place where a rushed rewrite grants an account to the wrong page.
45
+ */
46
+ export type CrossOriginConsentLookup = (signingOrigin: string) => Promise<CrossOriginConsent | undefined>;
47
+ /**
48
+ * What the host does about the request, decided before anything is derived or signed.
49
+ *
50
+ * `basis` exists so the UI can say something true. A named requester and a wildcard are both a
51
+ * prompt, but they are not the same prompt: one origin vouched for this specific site, the other
52
+ * left its door open to everyone.
53
+ */
54
+ export type AccessDecision = {
55
+ kind: 'same-origin';
56
+ } | {
57
+ kind: 'ask';
58
+ basis: 'named' | 'wildcard' | 'loopback';
59
+ } | {
60
+ kind: 'blocked';
61
+ };
62
+ /** What the app is told when a request is refused, so it can offer the onchain path instead. */
63
+ export type CrossOriginBlocked = {
64
+ message: string;
65
+ type: 'cross-origin-blocked';
66
+ windowOrigin: string;
67
+ signingOrigin: string;
68
+ };
69
+ export declare function crossOriginBlockedError(request: {
70
+ windowOrigin: string;
71
+ signingOrigin: string;
72
+ }): CrossOriginBlocked;
73
+ /**
74
+ * One spelling for one origin.
75
+ *
76
+ * A browser hands over `https://game.example` already lowercased and without a trailing slash; a
77
+ * table maintained by hand does not. Normalising both sides costs nothing and prevents the failure
78
+ * that would otherwise be silent in the dangerous direction: an entry with a trailing slash that
79
+ * never matches, leaving an origin's consent quietly ineffective.
80
+ *
81
+ * It normalises SPELLING and nothing else. No wildcards, no subdomain rules, no port tolerance:
82
+ * every relaxation of this comparison is a way for one origin to be granted what was decided for
83
+ * another.
84
+ */
85
+ export declare function normalizeOrigin(origin: string): string;
86
+ /**
87
+ * One entry of a table keyed by origin, matched with only SPELLING normalised.
88
+ *
89
+ * Here rather than in the host that holds the table, because it is MATCHING: which key answers for
90
+ * which origin decides whether a credential is minted with nobody in the loop, and that comparison
91
+ * belongs where tests reach it. A host supplies the table and calls this.
92
+ */
93
+ export declare function lookupByOrigin<T>(table: Record<string, T>, origin: string): T | undefined;
94
+ /**
95
+ * A LOCAL DEVELOPMENT PAGE, matched by parsing rather than by looking for a substring.
96
+ *
97
+ * `origin.includes('localhost')` also matches `https://localhost.evil.com`, which is a real domain
98
+ * a real attacker can register, so the check is: a real URL, whose own `origin` is all the string
99
+ * contains, over http(s), whose HOSTNAME IS EXACTLY a loopback name.
100
+ *
101
+ * A page cannot claim to be `http://localhost:3000` unless it is served from there, so the threat
102
+ * this admits is not a remote site: it is untrusted code the user runs locally. That is why the
103
+ * allowance below is a property of a development build of the host and not of the one holding real
104
+ * accounts.
105
+ */
106
+ export declare function isLoopbackOrigin(origin: string): boolean;
107
+ /**
108
+ * Decide, before anything is derived, whether this window may be signed for at all.
109
+ *
110
+ * Default-deny is the point: the absence of an entry is a refusal, not a prompt. A prompt naming
111
+ * two origins is not a decision a user can make well, and the one case where it carries real
112
+ * information (an origin that deliberately opened itself to another) is exactly the case an entry
113
+ * records.
114
+ */
115
+ export declare function resolveAccess(request: {
116
+ windowOrigin: string;
117
+ signingOrigin: string;
118
+ }, options: {
119
+ consentFor: CrossOriginConsentLookup;
120
+ allowLoopbackRequesters?: boolean;
121
+ }): Promise<AccessDecision>;
122
+ /**
123
+ * Whether the prompt for this decision has to be confirmed twice.
124
+ *
125
+ * Only where nobody vouched for the requester. A wildcard says the signing origin accepts anyone,
126
+ * and a loopback allowance says a build flag does, so in both cases the only party who knows
127
+ * whether this particular site should be trusted is the person reading the screen. Making them say
128
+ * so twice is not friction for its own sake: it is the difference between clicking through a
129
+ * dialog and answering it.
130
+ */
131
+ export declare function requiresSecondConfirmation(decision: AccessDecision): boolean;
132
+ /**
133
+ * The access gate itself: one confirmation in, the state of the gate out.
134
+ *
135
+ * A counter and two comparisons, and it is here rather than in the component holding them because
136
+ * of what it decides. It is the last thing between a request and an account, it is the only new
137
+ * logic in this feature that a human clicks through, and a component in the host is somewhere no
138
+ * test in this repository can reach.
139
+ *
140
+ * A decision that is not `ask` can never be granted through this path: `same-origin` needs no
141
+ * confirming and `blocked` must not be confirmable at all, so the guard is a property of the
142
+ * function rather than of whichever markup happens to render a button.
143
+ */
144
+ export declare function confirmAccess(decision: AccessDecision, confirmationsGiven: number): {
145
+ confirmationsGiven: number;
146
+ accessGranted: boolean;
147
+ };
148
+ /** How many confirmations this decision needs, for a UI that wants to say so. */
149
+ export declare function confirmationsRequired(decision: AccessDecision): number;
150
+ /**
151
+ * Which (chain, contract) pairs may be signed with NOBODY IN THE LOOP, given how access was decided.
152
+ *
153
+ * SAME ORIGIN: the host's table for that origin, unchanged. Auto-signing there removes a prompt
154
+ * that carried nothing, since an origin that can derive this signer silently gains nothing from a
155
+ * delegation bounded to its own contract.
156
+ *
157
+ * NAMED CROSS-ORIGIN: the pair must be listed for BOTH origins. The argument is that once access
158
+ * has been granted, the requester holds exactly the signer the signing origin holds, so a
159
+ * delegation at a contract the signing origin is already allowlisted for is one its own flow would
160
+ * have minted anyway. That argument needs both sides named, and it is why a wildcard does not
161
+ * qualify: "anyone may ask" says nothing about who this is, so nothing is minted without a human.
162
+ */
163
+ export declare function autoSignLookup(options: {
164
+ windowOrigin: string;
165
+ signingOrigin: string;
166
+ access: AccessDecision;
167
+ allowlistFor: (origin: string) => DelegationTarget[];
168
+ }): AllowlistLookup;
169
+ //# sourceMappingURL=access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAE9F;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,kB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EAAE,OAAO,CAAA;CAAC,GAChF,OAAO,CAAC,cAAc,CAAC,CA0BzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAE5E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC5B,QAAQ,EAAE,cAAc,EACxB,kBAAkB,EAAE,MAAM,GACxB;IAAC,kBAAkB,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAC,CAOtD;AAED,iFAAiF;AACjF,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CAEtE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,cAAc,CAAC;IACvB,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,gBAAgB,EAAE,CAAC;CACrD,GAAG,eAAe,CAYlB"}
package/dist/access.js ADDED
@@ -0,0 +1,163 @@
1
+ import { allowlistLookup } from './permissions.js';
2
+ export function crossOriginBlockedError(request) {
3
+ return {
4
+ // Named in full, both of them. An app that gets this back has almost always misconfigured
5
+ // `signingOrigin`, and the two strings side by side are the whole diagnosis.
6
+ message: `${request.windowOrigin} may not request an account for ${request.signingOrigin}`,
7
+ type: 'cross-origin-blocked',
8
+ windowOrigin: request.windowOrigin,
9
+ signingOrigin: request.signingOrigin,
10
+ };
11
+ }
12
+ /**
13
+ * One spelling for one origin.
14
+ *
15
+ * A browser hands over `https://game.example` already lowercased and without a trailing slash; a
16
+ * table maintained by hand does not. Normalising both sides costs nothing and prevents the failure
17
+ * that would otherwise be silent in the dangerous direction: an entry with a trailing slash that
18
+ * never matches, leaving an origin's consent quietly ineffective.
19
+ *
20
+ * It normalises SPELLING and nothing else. No wildcards, no subdomain rules, no port tolerance:
21
+ * every relaxation of this comparison is a way for one origin to be granted what was decided for
22
+ * another.
23
+ */
24
+ export function normalizeOrigin(origin) {
25
+ return origin.trim().replace(/\/+$/, '').toLowerCase();
26
+ }
27
+ /**
28
+ * One entry of a table keyed by origin, matched with only SPELLING normalised.
29
+ *
30
+ * Here rather than in the host that holds the table, because it is MATCHING: which key answers for
31
+ * which origin decides whether a credential is minted with nobody in the loop, and that comparison
32
+ * belongs where tests reach it. A host supplies the table and calls this.
33
+ */
34
+ export function lookupByOrigin(table, origin) {
35
+ const wanted = normalizeOrigin(origin);
36
+ for (const key of Object.keys(table)) {
37
+ if (normalizeOrigin(key) === wanted) {
38
+ return table[key];
39
+ }
40
+ }
41
+ return undefined;
42
+ }
43
+ /**
44
+ * A LOCAL DEVELOPMENT PAGE, matched by parsing rather than by looking for a substring.
45
+ *
46
+ * `origin.includes('localhost')` also matches `https://localhost.evil.com`, which is a real domain
47
+ * a real attacker can register, so the check is: a real URL, whose own `origin` is all the string
48
+ * contains, over http(s), whose HOSTNAME IS EXACTLY a loopback name.
49
+ *
50
+ * A page cannot claim to be `http://localhost:3000` unless it is served from there, so the threat
51
+ * this admits is not a remote site: it is untrusted code the user runs locally. That is why the
52
+ * allowance below is a property of a development build of the host and not of the one holding real
53
+ * accounts.
54
+ */
55
+ export function isLoopbackOrigin(origin) {
56
+ const normalised = normalizeOrigin(origin);
57
+ let url;
58
+ try {
59
+ url = new URL(normalised);
60
+ }
61
+ catch {
62
+ return false;
63
+ }
64
+ // Anything carrying a path, credentials or a query is not an origin, and must not be treated as
65
+ // one: `http://localhost@evil.example` parses, and its host is `evil.example`.
66
+ if (url.origin.toLowerCase() !== normalised) {
67
+ return false;
68
+ }
69
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
70
+ return false;
71
+ }
72
+ return url.hostname === 'localhost' || url.hostname === '127.0.0.1' || url.hostname === '[::1]';
73
+ }
74
+ /**
75
+ * Decide, before anything is derived, whether this window may be signed for at all.
76
+ *
77
+ * Default-deny is the point: the absence of an entry is a refusal, not a prompt. A prompt naming
78
+ * two origins is not a decision a user can make well, and the one case where it carries real
79
+ * information (an origin that deliberately opened itself to another) is exactly the case an entry
80
+ * records.
81
+ */
82
+ export async function resolveAccess(request, options) {
83
+ const windowOrigin = normalizeOrigin(request.windowOrigin);
84
+ const signingOrigin = normalizeOrigin(request.signingOrigin);
85
+ if (windowOrigin === signingOrigin) {
86
+ return { kind: 'same-origin' };
87
+ }
88
+ const consent = await options.consentFor(signingOrigin);
89
+ // An explicit naming wins over every fallback below, including the loopback allowance: an origin
90
+ // that listed `http://localhost:5173` itself has vouched for it, which is more than a build flag
91
+ // can say.
92
+ if (Array.isArray(consent) && consent.map(normalizeOrigin).includes(windowOrigin)) {
93
+ return { kind: 'ask', basis: 'named' };
94
+ }
95
+ if (consent === '*') {
96
+ return { kind: 'ask', basis: 'wildcard' };
97
+ }
98
+ if (options.allowLoopbackRequesters && isLoopbackOrigin(windowOrigin)) {
99
+ return { kind: 'ask', basis: 'loopback' };
100
+ }
101
+ return { kind: 'blocked' };
102
+ }
103
+ /**
104
+ * Whether the prompt for this decision has to be confirmed twice.
105
+ *
106
+ * Only where nobody vouched for the requester. A wildcard says the signing origin accepts anyone,
107
+ * and a loopback allowance says a build flag does, so in both cases the only party who knows
108
+ * whether this particular site should be trusted is the person reading the screen. Making them say
109
+ * so twice is not friction for its own sake: it is the difference between clicking through a
110
+ * dialog and answering it.
111
+ */
112
+ export function requiresSecondConfirmation(decision) {
113
+ return decision.kind === 'ask' && decision.basis !== 'named';
114
+ }
115
+ /**
116
+ * The access gate itself: one confirmation in, the state of the gate out.
117
+ *
118
+ * A counter and two comparisons, and it is here rather than in the component holding them because
119
+ * of what it decides. It is the last thing between a request and an account, it is the only new
120
+ * logic in this feature that a human clicks through, and a component in the host is somewhere no
121
+ * test in this repository can reach.
122
+ *
123
+ * A decision that is not `ask` can never be granted through this path: `same-origin` needs no
124
+ * confirming and `blocked` must not be confirmable at all, so the guard is a property of the
125
+ * function rather than of whichever markup happens to render a button.
126
+ */
127
+ export function confirmAccess(decision, confirmationsGiven) {
128
+ if (decision.kind !== 'ask') {
129
+ return { confirmationsGiven, accessGranted: false };
130
+ }
131
+ const given = confirmationsGiven + 1;
132
+ const required = requiresSecondConfirmation(decision) ? 2 : 1;
133
+ return { confirmationsGiven: given, accessGranted: given >= required };
134
+ }
135
+ /** How many confirmations this decision needs, for a UI that wants to say so. */
136
+ export function confirmationsRequired(decision) {
137
+ return requiresSecondConfirmation(decision) ? 2 : 1;
138
+ }
139
+ /**
140
+ * Which (chain, contract) pairs may be signed with NOBODY IN THE LOOP, given how access was decided.
141
+ *
142
+ * SAME ORIGIN: the host's table for that origin, unchanged. Auto-signing there removes a prompt
143
+ * that carried nothing, since an origin that can derive this signer silently gains nothing from a
144
+ * delegation bounded to its own contract.
145
+ *
146
+ * NAMED CROSS-ORIGIN: the pair must be listed for BOTH origins. The argument is that once access
147
+ * has been granted, the requester holds exactly the signer the signing origin holds, so a
148
+ * delegation at a contract the signing origin is already allowlisted for is one its own flow would
149
+ * have minted anyway. That argument needs both sides named, and it is why a wildcard does not
150
+ * qualify: "anyone may ask" says nothing about who this is, so nothing is minted without a human.
151
+ */
152
+ export function autoSignLookup(options) {
153
+ if (options.access.kind === 'same-origin') {
154
+ return allowlistLookup(options.allowlistFor(normalizeOrigin(options.windowOrigin)));
155
+ }
156
+ if (options.access.kind === 'ask' && options.access.basis === 'named') {
157
+ const requester = allowlistLookup(options.allowlistFor(normalizeOrigin(options.windowOrigin)));
158
+ const owner = allowlistLookup(options.allowlistFor(normalizeOrigin(options.signingOrigin)));
159
+ return (request) => requester(request) && owner(request);
160
+ }
161
+ return () => false;
162
+ }
163
+ //# sourceMappingURL=access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.js","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAA8C,MAAM,kBAAkB,CAAC;AAsE9F,MAAM,UAAU,uBAAuB,CAAC,OAAsD;IAC7F,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M,KAAK,GAAG,eAAe,CAAC,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QAC5F,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC;AACpB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -37,4 +37,6 @@ export declare function fromPrivateKey(key: string | Uint8Array): string;
37
37
  export type * from './types.js';
38
38
  export * from './crypto.js';
39
39
  export * from './permissions.js';
40
+ export * from './access.js';
41
+ export * from './oauth-callback.js';
40
42
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,KAAK,EAAC,MAAM,cAAc,CAAC;AAInC,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAC;AAClE,OAAO,KAAK,EAAC,aAAa,EAAE,gBAAgB,EAAE,aAAa,EAAE,iBAAiB,EAAkB,MAAM,YAAY,CAAC;AAEnH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD;AACD,wBAAgB,eAAe,IAAI,MAAM,CAExC;AACD,wBAAgB,iCAAiC,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,MAAM,EAAE,GAAG,MAAM,CAEhG;AAMD,OAAO,EAAC,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,KAAK,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAEhH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,KAAK,MAAM,EAAE,GAAG,MAAM,CAE1E;AAED,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,KAAK,MAAM,EAAE,GAAG,KAAK,MAAM,EAAE,CAG1E;AAED,wB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,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AACD,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED,wBAAgB,IAAI,CAAC,GAAG,EAAE,OAAO,QAEhC;AAGD,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM;;;EAUpC;AAED,wBAAgB,WAAW,CAAC,qBAAqB,EAAE,MAAM,GAAG,MAAM,CAUjE;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAK9D;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAG/D;AAGD,mBAAmB,YAAY,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -152,4 +152,6 @@ export function fromPrivateKey(key) {
152
152
  }
153
153
  export * from './crypto.js';
154
154
  export * from './permissions.js';
155
+ export * from './access.js';
156
+ export * from './oauth-callback.js';
155
157
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,kBAAkB,EAAC,MAAM,cAAc,CAAC;AACnE,OAAO,EAAC,UAAU,EAAE,UAAU,EAAC,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAC,QAAQ,EAAC,MAAM,gCAAgC,CAAC;AACxD,OAAO,EAAC,KAAK,EAAC,MAAM,cAAc,CAAC;AACnC,OAAO,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAC,SAAS,EAAC,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AAIxD,MAAM,UAAU,gBAAg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AE,EAAE,CAAC,CAAC;QACxC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QAClB,WAAW,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,4BAA4B;IAC7E,CAAC;IACD,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,GAAwB;IACrD,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,GAAG,CAAC,CAAC;IACxD,MAAM,MAAM,GAAG,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACxE,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAClD,OAAO,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,eAAe;AAClE,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAwB;IACtD,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAChD,OAAO,aAAa,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;AAC1D,CAAC;AAID,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { Redirection } from './types.js';
2
+ /**
3
+ * WHAT THE POPUP MUST STILL KNOW WHEN IT COMES BACK FROM AN OAUTH PROVIDER.
4
+ *
5
+ * The OAuth round trip is a full page load: the popup navigates away to Google, comes back as a NEW
6
+ * document, and remembers nothing. Everything it needs has to be in the callback URL, so anything
7
+ * the app put on the popup URL and this list does not name is GONE, silently, and only on the OAuth
8
+ * path. That is what makes an omission here so hard to notice: the same app works by email and
9
+ * quietly loses a capability by Google.
10
+ *
11
+ * `permissions` is the case that proves it. It was missing for as long as the feature existed, so a
12
+ * user signing in with Google got an account with no credentials AND no refusal explaining it,
13
+ * which is exactly the "nobody asked" versus "you declined" ambiguity the per-entry outcomes exist
14
+ * to remove.
15
+ *
16
+ * A LIST, in one place, rather than a variable per parameter at the call site: the previous shape
17
+ * (one hand-concatenated string fragment each) is what let a parameter be forgotten with no error
18
+ * anywhere. Adding a parameter to the popup URL means adding it here.
19
+ */
20
+ export declare const CARRIED_THROUGH_OAUTH: readonly ["account-type", "permissions", "domain-redirect-public-key", "eruda", "debug", "log", "forceBroadcastChannel"];
21
+ /**
22
+ * The URL the OAuth provider sends the user back to.
23
+ *
24
+ * Pure, and here rather than in the provider package, because what it encodes is the popup URL
25
+ * CONTRACT: one side of it is written by `@etherplay/connect`, the other read by the host, and this
26
+ * is the point where the two are re-joined after a full page load. A test can reach it here.
27
+ *
28
+ * Built with `URLSearchParams` rather than concatenated. Every value in it is data from somewhere
29
+ * else (an origin, a JSON document, a public key), and hand-concatenation is how one containing `&`
30
+ * or `#` stops being one parameter and becomes several.
31
+ */
32
+ export declare function buildOAuthCallbackUrl(options: {
33
+ baseUrl: string;
34
+ redirection: Redirection;
35
+ /** the OAuth provider id, e.g. `google` */
36
+ provider: string;
37
+ /** for multi-provider brokers (auth0), the connection to use */
38
+ connection?: string;
39
+ /** the popup URL as it stands right now, which is where the carried parameters come from */
40
+ current: URLSearchParams;
41
+ }): string;
42
+ //# sourceMappingURL=oauth-callback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-callback.d.ts","sourceRoot":"","sources":["../src/oauth-callback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AAE5C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,qBAAqB,0HAexB,CAAC;AAEX;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,WAAW,CAAC;IACzB,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4FAA4F;IAC5F,OAAO,EAAE,eAAe,CAAC;CACzB,GAAG,MAAM,CAwBT"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * WHAT THE POPUP MUST STILL KNOW WHEN IT COMES BACK FROM AN OAUTH PROVIDER.
3
+ *
4
+ * The OAuth round trip is a full page load: the popup navigates away to Google, comes back as a NEW
5
+ * document, and remembers nothing. Everything it needs has to be in the callback URL, so anything
6
+ * the app put on the popup URL and this list does not name is GONE, silently, and only on the OAuth
7
+ * path. That is what makes an omission here so hard to notice: the same app works by email and
8
+ * quietly loses a capability by Google.
9
+ *
10
+ * `permissions` is the case that proves it. It was missing for as long as the feature existed, so a
11
+ * user signing in with Google got an account with no credentials AND no refusal explaining it,
12
+ * which is exactly the "nobody asked" versus "you declined" ambiguity the per-entry outcomes exist
13
+ * to remove.
14
+ *
15
+ * A LIST, in one place, rather than a variable per parameter at the call site: the previous shape
16
+ * (one hand-concatenated string fragment each) is what let a parameter be forgotten with no error
17
+ * anywhere. Adding a parameter to the popup URL means adding it here.
18
+ */
19
+ export const CARRIED_THROUGH_OAUTH = [
20
+ 'account-type',
21
+ /** what the app asked for beyond the account itself, as JSON */
22
+ 'permissions',
23
+ /**
24
+ * Same-Origin Callback Bridge: the parent's public key. It must survive this round trip for the
25
+ * encrypted result to be deliverable at all when the opener link has been severed, which is the
26
+ * situation the bridge exists for.
27
+ */
28
+ 'domain-redirect-public-key',
29
+ 'eruda',
30
+ 'debug',
31
+ 'log',
32
+ /** testing aid: forces the BroadcastChannel delivery path on the bridge page */
33
+ 'forceBroadcastChannel',
34
+ ];
35
+ /**
36
+ * The URL the OAuth provider sends the user back to.
37
+ *
38
+ * Pure, and here rather than in the provider package, because what it encodes is the popup URL
39
+ * CONTRACT: one side of it is written by `@etherplay/connect`, the other read by the host, and this
40
+ * is the point where the two are re-joined after a full page load. A test can reach it here.
41
+ *
42
+ * Built with `URLSearchParams` rather than concatenated. Every value in it is data from somewhere
43
+ * else (an origin, a JSON document, a public key), and hand-concatenation is how one containing `&`
44
+ * or `#` stops being one parameter and becomes several.
45
+ */
46
+ export function buildOAuthCallbackUrl(options) {
47
+ const params = new URLSearchParams({
48
+ 'oauth-callback': 'true',
49
+ 'oauth-redirection': 'true',
50
+ type: 'oauth',
51
+ origin: options.redirection.windowOrigin,
52
+ signingOrigin: options.redirection.signingOrigin,
53
+ id: options.redirection.id,
54
+ 'oauth-provider': options.provider,
55
+ });
56
+ if (options.connection) {
57
+ params.set('oauth-connection', options.connection);
58
+ }
59
+ for (const name of CARRIED_THROUGH_OAUTH) {
60
+ if (options.current.has(name)) {
61
+ // Presence is meaningful on its own: `?debug` and `?debug=1` both mean debug, and a
62
+ // parameter that was present must not come back absent.
63
+ params.set(name, options.current.get(name) || '');
64
+ }
65
+ }
66
+ return `${options.baseUrl}/login/?${params.toString()}`;
67
+ }
68
+ //# sourceMappingURL=oauth-callback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-callback.js","sourceRoot":"","sources":["../src/oauth-callback.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACpC,cAAc;IACd,gEAAgE;IAChE,aAAa;IACb;;;;OAIG;IACH,4BAA4B;IAC5B,OAAO;IACP,OAAO;IACP,KAAK;IACL,gFAAgF;IAChF,uBAAuB;CACd,CAAC;AAEX;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CAAC,OASrC;IACA,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC;QAClC,gBAAgB,EAAE,MAAM;QACxB,mBAAmB,EAAE,MAAM;QAC3B,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,YAAY;QACxC,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,aAAa;QAChD,EAAE,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE;QAC1B,gBAAgB,EAAE,OAAO,CAAC,QAAQ;KAClC,CAAC,CAAC;IAEH,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACxB,MAAM,CAAC,GAAG,CAAC,kBAAkB,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,qBAAqB,EAAE,CAAC;QAC1C,IAAI,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,oFAAoF;YACpF,wDAAwD;YACxD,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACnD,CAAC;IACF,CAAC;IAED,OAAO,GAAG,OAAO,CAAC,OAAO,WAAW,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;AACzD,CAAC"}
package/dist/types.d.ts CHANGED
@@ -58,8 +58,6 @@ export type PermissionRequest = DelegationPermissionRequest | UnrecognizedPermis
58
58
  export type OriginApprovalRequest = {
59
59
  windowOrigin: string;
60
60
  signingOrigin: string;
61
- /** the account-access gate: this window is not the origin being signed for */
62
- requestingAccess: boolean;
63
61
  /** what the app declared at connect time; empty when it asked for nothing */
64
62
  permissions: PermissionRequest[];
65
63
  };
@@ -81,8 +79,11 @@ export type PermissionOutcome = {
81
79
  /**
82
80
  * `denied`: a human said no.
83
81
  * `unsupported`: this wallet does not understand the request, so nobody was asked.
82
+ * `sign-on-demand`: nothing was pre-generated because this owner is a LIVE signer that
83
+ * can be asked at the moment of use, which is worth more than consent at the door.
84
+ * Not a refusal: call `getDelegation` when the credential is actually needed.
84
85
  */
85
- reason: 'denied' | 'unsupported';
86
+ reason: 'denied' | 'unsupported' | 'sign-on-demand';
86
87
  };
87
88
  /**
88
89
  * A delegation credential, cached from the bytes that were signed.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,IAAI;IAC7D,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,CAAC,CAAC;CACT,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,OAAO,CAAC;IAEd,QAAQ,EAAE;QAAC,EAAE,EAAE,MAAM,CAAA;KAAC,GAAG,CAAC,EAAE,GAAG;QAAC,UAAU,EAAE,MAAM,CAAA;KAAC,CAAC,CAAC;CACrD,GAAG,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAA;CAAC,GAAG;IAAC,QAAQ,EAAE,KAAK,CAAA;CAAC,CAAC,CAAC;AAE3C,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,IAAI;IAC1D,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;IACT,IAAI,EAAE,KAAK,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,cAAc,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,cAAc,GAAG,iBAAiB,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;AAIxH;;;;;GAKG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACzC,IAAI,EAAE,YAAY,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,KAAK,MAAM,EAAE,CAAC;CACxB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,6BAA6B,G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C,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAC,CAAC;AAEpF,MAAM,WAAW,YAAa,SAAQ,QAAQ,CAAC,SAAS,CAAC;IACxD,IAAI,CAAC,QAAQ,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,OAAO,CAAC,SAAS,EAAE,aAAa,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5E,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,oBAAoB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,YAAY,CAAC,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etherplay/connect-core",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "core functionality for @etherplay/connect and other",
5
5
  "homepage": "https://github.com/wighawag/etherplay-connect#readme",
6
6
  "repository": {
package/src/access.ts ADDED
@@ -0,0 +1,257 @@
1
+ import {allowlistLookup, type AllowlistLookup, type DelegationTarget} from './permissions.js';
2
+
3
+ /**
4
+ * WHO MAY ASK FOR AN ACCOUNT THAT IS NOT THEIRS.
5
+ *
6
+ * A request is CROSS-ORIGIN when the window that opened the wallet is not the origin being signed
7
+ * for: `evil.example` opening the popup with `signingOrigin=https://game.example` is asking for the
8
+ * signer `game.example` derives, which is the whole of that account's authority there.
9
+ *
10
+ * The answer is NO, unless the origin whose account is at stake has said otherwise. That default is
11
+ * affordable because there is now a way to do this properly: a delegation contract authorises MANY
12
+ * delegates, so a third-party site can bring its OWN origin signer and have the user register it
13
+ * onchain. That costs a transaction, which is why the consent list below still exists, but it means
14
+ * refusing is no longer refusing the use case.
15
+ *
16
+ * WHAT THIS IS NOT. It is not a guarantee that no page can obtain a cross-origin signer. In the
17
+ * external-wallet path the app asks the user's own wallet to sign the origin message with no host
18
+ * in the loop, and nothing here is consulted; the message text in the wallet's dialog is the only
19
+ * gate there. What this does guarantee is that THIS HOST will not hand over an account for an
20
+ * origin that did not agree to it.
21
+ *
22
+ * WHAT THE GUARANTEE RESTS ON, AND IT IS NOT IN THIS FILE. `windowOrigin` is a value the opener
23
+ * writes; nothing here authenticates it, so a page can claim to be `https://game.example` and be
24
+ * answered `same-origin`. What makes the lie worthless is DELIVERY, not this decision: the host
25
+ * posts the result with `targetOrigin: windowOrigin` and only ever adopts an opener whose
26
+ * `event.origin` matches, so a page that lies is instructing the browser to hand the account to a
27
+ * window it is not. A claimed origin is therefore safe to decide on and unsafe to act on any other
28
+ * way, and any future path that returns something to the app WITHOUT that origin lock breaks this
29
+ * module's guarantee without touching this module.
30
+ */
31
+
32
+ /**
33
+ * What one signing origin accepts.
34
+ *
35
+ * `'*'` means "anyone may ASK", which is emphatically not "anyone is trusted": there is still a
36
+ * human prompt, and it is a stronger one, because the host knows nothing about who is asking. An
37
+ * array is the meaningful form: named requesters, matched exactly.
38
+ */
39
+ export type CrossOriginConsent = '*' | string[];
40
+
41
+ /**
42
+ * How a host looks up that consent.
43
+ *
44
+ * ASYNCHRONOUS ON PURPOSE, while every implementation is a hardcoded table. The table is expected
45
+ * to become something fetched (a document served by the signing origin itself is self-attesting in
46
+ * the way a central list is not), and an async boundary drawn later is a rewrite of every call
47
+ * site, at the exact place where a rushed rewrite grants an account to the wrong page.
48
+ */
49
+ export type CrossOriginConsentLookup = (signingOrigin: string) => Promise<CrossOriginConsent | undefined>;
50
+
51
+ /**
52
+ * What the host does about the request, decided before anything is derived or signed.
53
+ *
54
+ * `basis` exists so the UI can say something true. A named requester and a wildcard are both a
55
+ * prompt, but they are not the same prompt: one origin vouched for this specific site, the other
56
+ * left its door open to everyone.
57
+ */
58
+ export type AccessDecision =
59
+ | {kind: 'same-origin'}
60
+ | {kind: 'ask'; basis: 'named' | 'wildcard' | 'loopback'}
61
+ | {kind: 'blocked'};
62
+
63
+ /** What the app is told when a request is refused, so it can offer the onchain path instead. */
64
+ export type CrossOriginBlocked = {
65
+ message: string;
66
+ type: 'cross-origin-blocked';
67
+ windowOrigin: string;
68
+ signingOrigin: string;
69
+ };
70
+
71
+ export function crossOriginBlockedError(request: {windowOrigin: string; signingOrigin: string}): CrossOriginBlocked {
72
+ return {
73
+ // Named in full, both of them. An app that gets this back has almost always misconfigured
74
+ // `signingOrigin`, and the two strings side by side are the whole diagnosis.
75
+ message: `${request.windowOrigin} may not request an account for ${request.signingOrigin}`,
76
+ type: 'cross-origin-blocked',
77
+ windowOrigin: request.windowOrigin,
78
+ signingOrigin: request.signingOrigin,
79
+ };
80
+ }
81
+
82
+ /**
83
+ * One spelling for one origin.
84
+ *
85
+ * A browser hands over `https://game.example` already lowercased and without a trailing slash; a
86
+ * table maintained by hand does not. Normalising both sides costs nothing and prevents the failure
87
+ * that would otherwise be silent in the dangerous direction: an entry with a trailing slash that
88
+ * never matches, leaving an origin's consent quietly ineffective.
89
+ *
90
+ * It normalises SPELLING and nothing else. No wildcards, no subdomain rules, no port tolerance:
91
+ * every relaxation of this comparison is a way for one origin to be granted what was decided for
92
+ * another.
93
+ */
94
+ export function normalizeOrigin(origin: string): string {
95
+ return origin.trim().replace(/\/+$/, '').toLowerCase();
96
+ }
97
+
98
+ /**
99
+ * One entry of a table keyed by origin, matched with only SPELLING normalised.
100
+ *
101
+ * Here rather than in the host that holds the table, because it is MATCHING: which key answers for
102
+ * which origin decides whether a credential is minted with nobody in the loop, and that comparison
103
+ * belongs where tests reach it. A host supplies the table and calls this.
104
+ */
105
+ export function lookupByOrigin<T>(table: Record<string, T>, origin: string): T | undefined {
106
+ const wanted = normalizeOrigin(origin);
107
+ for (const key of Object.keys(table)) {
108
+ if (normalizeOrigin(key) === wanted) {
109
+ return table[key];
110
+ }
111
+ }
112
+ return undefined;
113
+ }
114
+
115
+ /**
116
+ * A LOCAL DEVELOPMENT PAGE, matched by parsing rather than by looking for a substring.
117
+ *
118
+ * `origin.includes('localhost')` also matches `https://localhost.evil.com`, which is a real domain
119
+ * a real attacker can register, so the check is: a real URL, whose own `origin` is all the string
120
+ * contains, over http(s), whose HOSTNAME IS EXACTLY a loopback name.
121
+ *
122
+ * A page cannot claim to be `http://localhost:3000` unless it is served from there, so the threat
123
+ * this admits is not a remote site: it is untrusted code the user runs locally. That is why the
124
+ * allowance below is a property of a development build of the host and not of the one holding real
125
+ * accounts.
126
+ */
127
+ export function isLoopbackOrigin(origin: string): boolean {
128
+ const normalised = normalizeOrigin(origin);
129
+ let url: URL;
130
+ try {
131
+ url = new URL(normalised);
132
+ } catch {
133
+ return false;
134
+ }
135
+ // Anything carrying a path, credentials or a query is not an origin, and must not be treated as
136
+ // one: `http://localhost@evil.example` parses, and its host is `evil.example`.
137
+ if (url.origin.toLowerCase() !== normalised) {
138
+ return false;
139
+ }
140
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
141
+ return false;
142
+ }
143
+ return url.hostname === 'localhost' || url.hostname === '127.0.0.1' || url.hostname === '[::1]';
144
+ }
145
+
146
+ /**
147
+ * Decide, before anything is derived, whether this window may be signed for at all.
148
+ *
149
+ * Default-deny is the point: the absence of an entry is a refusal, not a prompt. A prompt naming
150
+ * two origins is not a decision a user can make well, and the one case where it carries real
151
+ * information (an origin that deliberately opened itself to another) is exactly the case an entry
152
+ * records.
153
+ */
154
+ export async function resolveAccess(
155
+ request: {windowOrigin: string; signingOrigin: string},
156
+ options: {consentFor: CrossOriginConsentLookup; allowLoopbackRequesters?: boolean},
157
+ ): Promise<AccessDecision> {
158
+ const windowOrigin = normalizeOrigin(request.windowOrigin);
159
+ const signingOrigin = normalizeOrigin(request.signingOrigin);
160
+
161
+ if (windowOrigin === signingOrigin) {
162
+ return {kind: 'same-origin'};
163
+ }
164
+
165
+ const consent = await options.consentFor(signingOrigin);
166
+
167
+ // An explicit naming wins over every fallback below, including the loopback allowance: an origin
168
+ // that listed `http://localhost:5173` itself has vouched for it, which is more than a build flag
169
+ // can say.
170
+ if (Array.isArray(consent) && consent.map(normalizeOrigin).includes(windowOrigin)) {
171
+ return {kind: 'ask', basis: 'named'};
172
+ }
173
+
174
+ if (consent === '*') {
175
+ return {kind: 'ask', basis: 'wildcard'};
176
+ }
177
+
178
+ if (options.allowLoopbackRequesters && isLoopbackOrigin(windowOrigin)) {
179
+ return {kind: 'ask', basis: 'loopback'};
180
+ }
181
+
182
+ return {kind: 'blocked'};
183
+ }
184
+
185
+ /**
186
+ * Whether the prompt for this decision has to be confirmed twice.
187
+ *
188
+ * Only where nobody vouched for the requester. A wildcard says the signing origin accepts anyone,
189
+ * and a loopback allowance says a build flag does, so in both cases the only party who knows
190
+ * whether this particular site should be trusted is the person reading the screen. Making them say
191
+ * so twice is not friction for its own sake: it is the difference between clicking through a
192
+ * dialog and answering it.
193
+ */
194
+ export function requiresSecondConfirmation(decision: AccessDecision): boolean {
195
+ return decision.kind === 'ask' && decision.basis !== 'named';
196
+ }
197
+
198
+ /**
199
+ * The access gate itself: one confirmation in, the state of the gate out.
200
+ *
201
+ * A counter and two comparisons, and it is here rather than in the component holding them because
202
+ * of what it decides. It is the last thing between a request and an account, it is the only new
203
+ * logic in this feature that a human clicks through, and a component in the host is somewhere no
204
+ * test in this repository can reach.
205
+ *
206
+ * A decision that is not `ask` can never be granted through this path: `same-origin` needs no
207
+ * confirming and `blocked` must not be confirmable at all, so the guard is a property of the
208
+ * function rather than of whichever markup happens to render a button.
209
+ */
210
+ export function confirmAccess(
211
+ decision: AccessDecision,
212
+ confirmationsGiven: number,
213
+ ): {confirmationsGiven: number; accessGranted: boolean} {
214
+ if (decision.kind !== 'ask') {
215
+ return {confirmationsGiven, accessGranted: false};
216
+ }
217
+ const given = confirmationsGiven + 1;
218
+ const required = requiresSecondConfirmation(decision) ? 2 : 1;
219
+ return {confirmationsGiven: given, accessGranted: given >= required};
220
+ }
221
+
222
+ /** How many confirmations this decision needs, for a UI that wants to say so. */
223
+ export function confirmationsRequired(decision: AccessDecision): number {
224
+ return requiresSecondConfirmation(decision) ? 2 : 1;
225
+ }
226
+
227
+ /**
228
+ * Which (chain, contract) pairs may be signed with NOBODY IN THE LOOP, given how access was decided.
229
+ *
230
+ * SAME ORIGIN: the host's table for that origin, unchanged. Auto-signing there removes a prompt
231
+ * that carried nothing, since an origin that can derive this signer silently gains nothing from a
232
+ * delegation bounded to its own contract.
233
+ *
234
+ * NAMED CROSS-ORIGIN: the pair must be listed for BOTH origins. The argument is that once access
235
+ * has been granted, the requester holds exactly the signer the signing origin holds, so a
236
+ * delegation at a contract the signing origin is already allowlisted for is one its own flow would
237
+ * have minted anyway. That argument needs both sides named, and it is why a wildcard does not
238
+ * qualify: "anyone may ask" says nothing about who this is, so nothing is minted without a human.
239
+ */
240
+ export function autoSignLookup(options: {
241
+ windowOrigin: string;
242
+ signingOrigin: string;
243
+ access: AccessDecision;
244
+ allowlistFor: (origin: string) => DelegationTarget[];
245
+ }): AllowlistLookup {
246
+ if (options.access.kind === 'same-origin') {
247
+ return allowlistLookup(options.allowlistFor(normalizeOrigin(options.windowOrigin)));
248
+ }
249
+
250
+ if (options.access.kind === 'ask' && options.access.basis === 'named') {
251
+ const requester = allowlistLookup(options.allowlistFor(normalizeOrigin(options.windowOrigin)));
252
+ const owner = allowlistLookup(options.allowlistFor(normalizeOrigin(options.signingOrigin)));
253
+ return (request) => requester(request) && owner(request);
254
+ }
255
+
256
+ return () => false;
257
+ }
package/src/index.ts CHANGED
@@ -189,3 +189,5 @@ export function fromPrivateKey(key: string | Uint8Array): string {
189
189
  export type * from './types.js';
190
190
  export * from './crypto.js';
191
191
  export * from './permissions.js';
192
+ export * from './access.js';
193
+ export * from './oauth-callback.js';
@@ -0,0 +1,82 @@
1
+ import type {Redirection} from './types.js';
2
+
3
+ /**
4
+ * WHAT THE POPUP MUST STILL KNOW WHEN IT COMES BACK FROM AN OAUTH PROVIDER.
5
+ *
6
+ * The OAuth round trip is a full page load: the popup navigates away to Google, comes back as a NEW
7
+ * document, and remembers nothing. Everything it needs has to be in the callback URL, so anything
8
+ * the app put on the popup URL and this list does not name is GONE, silently, and only on the OAuth
9
+ * path. That is what makes an omission here so hard to notice: the same app works by email and
10
+ * quietly loses a capability by Google.
11
+ *
12
+ * `permissions` is the case that proves it. It was missing for as long as the feature existed, so a
13
+ * user signing in with Google got an account with no credentials AND no refusal explaining it,
14
+ * which is exactly the "nobody asked" versus "you declined" ambiguity the per-entry outcomes exist
15
+ * to remove.
16
+ *
17
+ * A LIST, in one place, rather than a variable per parameter at the call site: the previous shape
18
+ * (one hand-concatenated string fragment each) is what let a parameter be forgotten with no error
19
+ * anywhere. Adding a parameter to the popup URL means adding it here.
20
+ */
21
+ export const CARRIED_THROUGH_OAUTH = [
22
+ 'account-type',
23
+ /** what the app asked for beyond the account itself, as JSON */
24
+ 'permissions',
25
+ /**
26
+ * Same-Origin Callback Bridge: the parent's public key. It must survive this round trip for the
27
+ * encrypted result to be deliverable at all when the opener link has been severed, which is the
28
+ * situation the bridge exists for.
29
+ */
30
+ 'domain-redirect-public-key',
31
+ 'eruda',
32
+ 'debug',
33
+ 'log',
34
+ /** testing aid: forces the BroadcastChannel delivery path on the bridge page */
35
+ 'forceBroadcastChannel',
36
+ ] as const;
37
+
38
+ /**
39
+ * The URL the OAuth provider sends the user back to.
40
+ *
41
+ * Pure, and here rather than in the provider package, because what it encodes is the popup URL
42
+ * CONTRACT: one side of it is written by `@etherplay/connect`, the other read by the host, and this
43
+ * is the point where the two are re-joined after a full page load. A test can reach it here.
44
+ *
45
+ * Built with `URLSearchParams` rather than concatenated. Every value in it is data from somewhere
46
+ * else (an origin, a JSON document, a public key), and hand-concatenation is how one containing `&`
47
+ * or `#` stops being one parameter and becomes several.
48
+ */
49
+ export function buildOAuthCallbackUrl(options: {
50
+ baseUrl: string;
51
+ redirection: Redirection;
52
+ /** the OAuth provider id, e.g. `google` */
53
+ provider: string;
54
+ /** for multi-provider brokers (auth0), the connection to use */
55
+ connection?: string;
56
+ /** the popup URL as it stands right now, which is where the carried parameters come from */
57
+ current: URLSearchParams;
58
+ }): string {
59
+ const params = new URLSearchParams({
60
+ 'oauth-callback': 'true',
61
+ 'oauth-redirection': 'true',
62
+ type: 'oauth',
63
+ origin: options.redirection.windowOrigin,
64
+ signingOrigin: options.redirection.signingOrigin,
65
+ id: options.redirection.id,
66
+ 'oauth-provider': options.provider,
67
+ });
68
+
69
+ if (options.connection) {
70
+ params.set('oauth-connection', options.connection);
71
+ }
72
+
73
+ for (const name of CARRIED_THROUGH_OAUTH) {
74
+ if (options.current.has(name)) {
75
+ // Presence is meaningful on its own: `?debug` and `?debug=1` both mean debug, and a
76
+ // parameter that was present must not come back absent.
77
+ params.set(name, options.current.get(name) || '');
78
+ }
79
+ }
80
+
81
+ return `${options.baseUrl}/login/?${params.toString()}`;
82
+ }
package/src/types.ts CHANGED
@@ -60,12 +60,15 @@ export type PermissionRequest = DelegationPermissionRequest | UnrecognizedPermis
60
60
  export type OriginApprovalRequest = {
61
61
  windowOrigin: string;
62
62
  signingOrigin: string;
63
- /** the account-access gate: this window is not the origin being signed for */
64
- requestingAccess: boolean;
65
63
  /** what the app declared at connect time; empty when it asked for nothing */
66
64
  permissions: PermissionRequest[];
67
65
  };
68
66
 
67
+ // There is deliberately NO `requestingAccess` flag here. Whether this window may be signed for is
68
+ // answered by `resolveAccess` (see access.ts), which compares the two origins by one rule and
69
+ // returns one of three answers. A boolean beside them would be the same predicate computed twice,
70
+ // by two comparisons that are free to drift, for a question only one of them is allowed to answer.
71
+
69
72
  /**
70
73
  * The answer to one request, and it is an ANSWER rather than an absence.
71
74
  *
@@ -86,8 +89,11 @@ export type PermissionOutcome =
86
89
  /**
87
90
  * `denied`: a human said no.
88
91
  * `unsupported`: this wallet does not understand the request, so nobody was asked.
92
+ * `sign-on-demand`: nothing was pre-generated because this owner is a LIVE signer that
93
+ * can be asked at the moment of use, which is worth more than consent at the door.
94
+ * Not a refusal: call `getDelegation` when the credential is actually needed.
89
95
  */
90
- reason: 'denied' | 'unsupported';
96
+ reason: 'denied' | 'unsupported' | 'sign-on-demand';
91
97
  };
92
98
 
93
99
  /**