pico-engine 1.4.0 → 1.6.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 +188 -0
- package/dist/RulesetRegistryLoaderFs.js +2 -0
- package/dist/auth/AuthService.js +601 -0
- package/dist/auth/index.js +8 -0
- package/dist/auth/webauthn.js +97 -0
- package/dist/bundledKrl.js +42 -0
- package/dist/cli.js +11 -0
- package/dist/identity/IdentityService.js +340 -0
- package/dist/identity/crossPico.js +238 -0
- package/dist/identity/dbHelpers.js +67 -0
- package/dist/identity/didcommIngressRoutes.js +44 -0
- package/dist/identity/didoModule.js +252 -0
- package/dist/identity/errors.js +11 -0
- package/dist/identity/establishSubscription.js +97 -0
- package/dist/identity/index.js +15 -0
- package/dist/identity/peerDid.js +9 -0
- package/dist/identity/skyIntro.js +194 -0
- package/dist/identity/skyProtocol.js +105 -0
- package/dist/identity/store.js +233 -0
- package/dist/identity/types.js +13 -0
- package/dist/identity/veramoDidComm.js +260 -0
- package/dist/identity/webvh.js +266 -0
- package/dist/identity/webvhCrypto.js +128 -0
- package/dist/identity/webvhRoutes.js +61 -0
- package/dist/index.js +100 -44
- package/dist/oauth/OAuthService.js +388 -0
- package/dist/oauth/acg.js +495 -0
- package/dist/oauth/channelEligibility.js +26 -0
- package/dist/oauth/errors.js +12 -0
- package/dist/oauth/index.js +21 -0
- package/dist/oauth/krlModule.js +27 -0
- package/dist/oauth/meshOAuth.js +43 -0
- package/dist/provisionRoot.js +118 -0
- package/dist/server.js +609 -15
- package/dist/uiChannelPolicies.js +48 -0
- package/krl/io.picolabs.did-o.krl +5 -1
- package/krl/io.picolabs.oauth.krl +48 -0
- package/krl/io.picolabs.pico-engine-ui.krl +106 -18
- package/krl/io.picolabs.subscription.krl +242 -23
- package/krl/io.picolabs.wrangler.krl +225 -16
- package/package.json +38 -9
- package/public/docs/krl/_sidebar.md +1 -0
- package/public/docs/krl/discovery.md +144 -0
- package/public/docs/krl/modules/ctx.md +8 -0
- package/public/docs/krl/modules/event.md +41 -0
- package/public/pico-engine-ui.css +1 -1
- package/public/pico-engine-ui.js +24 -20
- package/public/pico-labs-logo.png +0 -0
- package/src/RulesetRegistryLoaderFs.ts +2 -0
- package/src/auth/AuthService.ts +850 -0
- package/src/auth/index.ts +17 -0
- package/src/auth/webauthn.ts +182 -0
- package/src/bundledKrl.ts +42 -0
- package/src/cli.ts +11 -0
- package/src/identity/IdentityService.ts +571 -0
- package/src/identity/crossPico.ts +371 -0
- package/src/identity/dbHelpers.ts +51 -0
- package/src/identity/didcommIngressRoutes.ts +54 -0
- package/src/identity/didoModule.ts +388 -0
- package/src/identity/errors.ts +8 -0
- package/src/identity/establishSubscription.ts +160 -0
- package/src/identity/index.ts +24 -0
- package/src/identity/peerDid.ts +22 -0
- package/src/identity/skyIntro.ts +321 -0
- package/src/identity/skyProtocol.ts +192 -0
- package/src/identity/store.ts +343 -0
- package/src/identity/types.ts +63 -0
- package/src/identity/veramoDidComm.ts +363 -0
- package/src/identity/webvh.ts +325 -0
- package/src/identity/webvhCrypto.ts +200 -0
- package/src/identity/webvhRoutes.ts +64 -0
- package/src/index.ts +145 -53
- package/src/oauth/OAuthService.ts +510 -0
- package/src/oauth/acg.ts +666 -0
- package/src/oauth/channelEligibility.ts +26 -0
- package/src/oauth/errors.ts +10 -0
- package/src/oauth/index.ts +14 -0
- package/src/oauth/krlModule.ts +31 -0
- package/src/oauth/meshOAuth.ts +50 -0
- package/src/provisionRoot.ts +151 -0
- package/src/server.ts +700 -24
- package/src/uiChannelPolicies.ts +49 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export {
|
|
2
|
+
AuthService,
|
|
3
|
+
AuthError,
|
|
4
|
+
AuthServiceDeps,
|
|
5
|
+
StoredAccount,
|
|
6
|
+
CredentialInfo,
|
|
7
|
+
InviteInfo,
|
|
8
|
+
InvitePeek,
|
|
9
|
+
WhoAmI,
|
|
10
|
+
} from "./AuthService";
|
|
11
|
+
export {
|
|
12
|
+
WebAuthnAdapter,
|
|
13
|
+
WebAuthnCredentialKey,
|
|
14
|
+
VerifiedRegistration,
|
|
15
|
+
VerifiedAuthentication,
|
|
16
|
+
makeWebAuthnAdapter,
|
|
17
|
+
} from "./webauthn";
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateAuthenticationOptions,
|
|
3
|
+
generateRegistrationOptions,
|
|
4
|
+
verifyAuthenticationResponse,
|
|
5
|
+
verifyRegistrationResponse,
|
|
6
|
+
} from "@simplewebauthn/server";
|
|
7
|
+
import type {
|
|
8
|
+
AuthenticationResponseJSON,
|
|
9
|
+
AuthenticatorTransportFuture,
|
|
10
|
+
PublicKeyCredentialCreationOptionsJSON,
|
|
11
|
+
PublicKeyCredentialRequestOptionsJSON,
|
|
12
|
+
RegistrationResponseJSON,
|
|
13
|
+
} from "@simplewebauthn/server";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A stored credential's crypto material, as understood by the WebAuthn library.
|
|
17
|
+
* `publicKey` is the raw COSE key bytes.
|
|
18
|
+
*/
|
|
19
|
+
export interface WebAuthnCredentialKey {
|
|
20
|
+
id: string;
|
|
21
|
+
publicKey: Uint8Array;
|
|
22
|
+
counter: number;
|
|
23
|
+
transports?: AuthenticatorTransportFuture[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface VerifiedRegistration {
|
|
27
|
+
verified: boolean;
|
|
28
|
+
credential?: WebAuthnCredentialKey;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface VerifiedAuthentication {
|
|
32
|
+
verified: boolean;
|
|
33
|
+
newCounter: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Thin, injectable wrapper around `@simplewebauthn/server`.
|
|
38
|
+
*
|
|
39
|
+
* The engine treats WebAuthn purely as a ceremony/verification library — the
|
|
40
|
+
* challenge/credential/session stores are engine primitives (see AuthService).
|
|
41
|
+
* This interface is also the seam that lets tests supply a deterministic
|
|
42
|
+
* authenticator without a real device.
|
|
43
|
+
*/
|
|
44
|
+
export interface ExcludeCredentialDescriptor {
|
|
45
|
+
id: string;
|
|
46
|
+
transports?: AuthenticatorTransportFuture[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface WebAuthnAdapter {
|
|
50
|
+
generateRegistrationOptions(req: {
|
|
51
|
+
rpID: string;
|
|
52
|
+
rpName: string;
|
|
53
|
+
userID: Uint8Array;
|
|
54
|
+
userName: string;
|
|
55
|
+
userDisplayName: string;
|
|
56
|
+
excludeCredentials?: ExcludeCredentialDescriptor[];
|
|
57
|
+
/** When true, relax resident-key requirements so another authenticator can enroll. */
|
|
58
|
+
additionalPasskey?: boolean;
|
|
59
|
+
}): Promise<PublicKeyCredentialCreationOptionsJSON>;
|
|
60
|
+
|
|
61
|
+
verifyRegistration(req: {
|
|
62
|
+
response: RegistrationResponseJSON;
|
|
63
|
+
expectedChallenge: string;
|
|
64
|
+
expectedOrigin: string;
|
|
65
|
+
expectedRPID: string;
|
|
66
|
+
}): Promise<VerifiedRegistration>;
|
|
67
|
+
|
|
68
|
+
generateAuthenticationOptions(req: {
|
|
69
|
+
rpID: string;
|
|
70
|
+
}): Promise<PublicKeyCredentialRequestOptionsJSON>;
|
|
71
|
+
|
|
72
|
+
verifyAuthentication(req: {
|
|
73
|
+
response: AuthenticationResponseJSON;
|
|
74
|
+
expectedChallenge: string;
|
|
75
|
+
expectedOrigin: string;
|
|
76
|
+
expectedRPID: string;
|
|
77
|
+
credential: WebAuthnCredentialKey;
|
|
78
|
+
}): Promise<VerifiedAuthentication>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function makeWebAuthnAdapter(): WebAuthnAdapter {
|
|
82
|
+
return {
|
|
83
|
+
async generateRegistrationOptions(req) {
|
|
84
|
+
const excludeCredentials = (req.excludeCredentials || []).map((cred) => {
|
|
85
|
+
const id = trimBase64URLPadding(cred.id);
|
|
86
|
+
const transports = (cred.transports || []).filter(Boolean);
|
|
87
|
+
return transports.length > 0 ? { id, transports } : { id };
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return generateRegistrationOptions({
|
|
91
|
+
rpName: req.rpName,
|
|
92
|
+
rpID: req.rpID,
|
|
93
|
+
userID: req.userID as any,
|
|
94
|
+
userName: req.userName,
|
|
95
|
+
userDisplayName: req.userDisplayName,
|
|
96
|
+
attestationType: "none",
|
|
97
|
+
excludeCredentials,
|
|
98
|
+
authenticatorSelection: req.additionalPasskey
|
|
99
|
+
? {
|
|
100
|
+
residentKey: "preferred",
|
|
101
|
+
userVerification: "preferred",
|
|
102
|
+
}
|
|
103
|
+
: {
|
|
104
|
+
residentKey: "required",
|
|
105
|
+
userVerification: "preferred",
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
async verifyRegistration(req) {
|
|
111
|
+
const verification = await verifyRegistrationResponse({
|
|
112
|
+
response: req.response,
|
|
113
|
+
expectedChallenge: req.expectedChallenge,
|
|
114
|
+
expectedOrigin: req.expectedOrigin,
|
|
115
|
+
expectedRPID: req.expectedRPID,
|
|
116
|
+
requireUserVerification: false,
|
|
117
|
+
});
|
|
118
|
+
if (!verification.verified || !verification.registrationInfo) {
|
|
119
|
+
return { verified: false };
|
|
120
|
+
}
|
|
121
|
+
const cred = verification.registrationInfo.credential;
|
|
122
|
+
return {
|
|
123
|
+
verified: true,
|
|
124
|
+
credential: {
|
|
125
|
+
id: cred.id,
|
|
126
|
+
publicKey: cred.publicKey,
|
|
127
|
+
counter: cred.counter,
|
|
128
|
+
transports: mergeTransports(cred.transports, req.response),
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
async generateAuthenticationOptions(req) {
|
|
134
|
+
return generateAuthenticationOptions({
|
|
135
|
+
rpID: req.rpID,
|
|
136
|
+
userVerification: "preferred",
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
async verifyAuthentication(req) {
|
|
141
|
+
const verification = await verifyAuthenticationResponse({
|
|
142
|
+
response: req.response,
|
|
143
|
+
expectedChallenge: req.expectedChallenge,
|
|
144
|
+
expectedOrigin: req.expectedOrigin,
|
|
145
|
+
expectedRPID: req.expectedRPID,
|
|
146
|
+
credential: {
|
|
147
|
+
id: req.credential.id,
|
|
148
|
+
publicKey: req.credential.publicKey as any,
|
|
149
|
+
counter: req.credential.counter,
|
|
150
|
+
transports: req.credential.transports,
|
|
151
|
+
},
|
|
152
|
+
requireUserVerification: false,
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
verified: verification.verified,
|
|
156
|
+
newCounter:
|
|
157
|
+
verification.authenticationInfo?.newCounter ?? req.credential.counter,
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function trimBase64URLPadding(id: string): string {
|
|
164
|
+
return id.replace(/=+$/g, "");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function mergeTransports(
|
|
168
|
+
fromAttestation: AuthenticatorTransportFuture[] | undefined,
|
|
169
|
+
response: RegistrationResponseJSON
|
|
170
|
+
): AuthenticatorTransportFuture[] {
|
|
171
|
+
const merged = [...(fromAttestation || [])].filter(Boolean);
|
|
172
|
+
if (merged.length > 0) {
|
|
173
|
+
return merged;
|
|
174
|
+
}
|
|
175
|
+
if (response.authenticatorAttachment === "platform") {
|
|
176
|
+
return ["internal"];
|
|
177
|
+
}
|
|
178
|
+
if (response.authenticatorAttachment === "cross-platform") {
|
|
179
|
+
return ["usb", "ble", "nfc"];
|
|
180
|
+
}
|
|
181
|
+
return [];
|
|
182
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { toFileUrl } from "./utils/toFileUrl";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* OS-layer rulesets shipped inside the pico-engine package. On flush, these
|
|
7
|
+
* always reload from the running engine's krl/ directory so dev edits apply
|
|
8
|
+
* even when the pico was provisioned from a different absolute file:// path.
|
|
9
|
+
*/
|
|
10
|
+
export const BUNDLED_KRL_FILES = [
|
|
11
|
+
"io.picolabs.pico-engine-ui.krl",
|
|
12
|
+
"io.picolabs.wrangler.krl",
|
|
13
|
+
"io.picolabs.subscription.krl",
|
|
14
|
+
"io.picolabs.pds.krl",
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
export function bundledKrlDir(): string {
|
|
18
|
+
return path.resolve(__dirname, "..", "krl");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function resolveBundledKrlUrl(url: string): string {
|
|
22
|
+
let filename: string | null = null;
|
|
23
|
+
try {
|
|
24
|
+
const parsed = new URL(url);
|
|
25
|
+
if (parsed.protocol === "file:") {
|
|
26
|
+
filename = path.basename(parsed.pathname);
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
return url;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!filename || !BUNDLED_KRL_FILES.includes(filename)) {
|
|
33
|
+
return url;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const localPath = path.join(bundledKrlDir(), filename);
|
|
37
|
+
if (fs.existsSync(localPath)) {
|
|
38
|
+
return toFileUrl(localPath);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return url;
|
|
42
|
+
}
|
package/src/cli.ts
CHANGED
|
@@ -26,6 +26,10 @@ Environment Variables:
|
|
|
26
26
|
PORT - The port the http server should listen on. By default it's 3000
|
|
27
27
|
PICO_ENGINE_HOME - Where the database and other files should be stored. By default it's ~/.pico-engine/
|
|
28
28
|
PICO_ENGINE_BASE_URL - The public url prefix to reach this engine. By default it's http://localhost:$PORT
|
|
29
|
+
PICO_ENGINE_ALLOW_SELF_SIGNUP - Set to "true" or "1" to allow anyone to register a new account
|
|
30
|
+
after the engine is bootstrapped. Default is false (login only; bootstrap and invite still work).
|
|
31
|
+
PICO_ENGINE_ALLOW_LOCALHOST_C - Set to "0" to require passkey session on /c/* even from localhost.
|
|
32
|
+
Default (unset) allows localhost without session for in-engine ctx:event HTTP loops. See MEMORY.md.
|
|
29
33
|
`);
|
|
30
34
|
process.exit(0);
|
|
31
35
|
}
|
|
@@ -53,6 +57,13 @@ if (
|
|
|
53
57
|
env.base_url = process.env.PICO_ENGINE_BASE_URL;
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
const allowSelfSignupEnv = process.env.PICO_ENGINE_ALLOW_SELF_SIGNUP;
|
|
61
|
+
if (allowSelfSignupEnv === "true" || allowSelfSignupEnv === "1") {
|
|
62
|
+
env.allowSelfSignup = true;
|
|
63
|
+
} else if (allowSelfSignupEnv === "false" || allowSelfSignupEnv === "0") {
|
|
64
|
+
env.allowSelfSignup = false;
|
|
65
|
+
}
|
|
66
|
+
|
|
56
67
|
startEngine(env).catch((err) => {
|
|
57
68
|
console.error("Failed to start engine.");
|
|
58
69
|
console.error(err);
|