@calimero-network/mero-js 22.8.0 → 22.9.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/dist/admin-api/admin-client.d.ts +17 -1
- package/dist/admin-api/admin-client.js +18 -0
- package/dist/admin-api/admin-types.d.ts +34 -0
- package/dist/device-cert/device-cert.d.ts +11 -0
- package/dist/device-cert/device-cert.js +1 -2
- package/dist/device-cert/device-scope.d.ts +58 -0
- package/dist/device-cert/device-scope.js +76 -0
- package/dist/device-cert/index.d.ts +2 -0
- package/dist/device-cert/index.js +1 -0
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +4 -4
- package/dist/index.cjs +177 -19
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.mjs +177 -19
- package/dist/index.mjs.map +4 -4
- package/dist/invitation/index.d.ts +2 -0
- package/dist/invitation/index.js +2 -0
- package/dist/invitation/invitation.d.ts +106 -0
- package/dist/invitation/invitation.js +104 -0
- package/dist/namespace-op/namespace-op.js +4 -14
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpClient, HTTPError } from '../http-client/index.js';
|
|
2
|
-
import type { HealthStatus, ReadinessStatus, AdminAuthStatus, InstallApplicationRequest, InstallApplicationResponseData, InstallDevApplicationRequest, UninstallApplicationResponseData, ListApplicationsResponseData, GetApplicationResponseData, ApplicationVersionEntry, GetApplicationAbiResponseData, GetLatestVersionResponseData, ListPackagesResponseData, ListVersionsResponseData, CreateContextRequest, CreateContextResponseData, DeleteContextResponseData, GetContextsResponseData, Context, GenerateContextIdentityResponseData, GetContextIdentitiesResponseData, JoinContextResponseData, JoinSubgroupInheritanceResponseData, ContextGroupResponseData, ContextStorageResponseData, InviteSpecializedNodeRequest, InviteSpecializedNodeResponseData, UpdateContextApplicationRequest, ResyncContextRequest, ResyncContextResponseData, ContextsWithExecutorsResponseData, UploadBlobRequest, UploadBlobResponseData, DeleteBlobResponseData, ListBlobsResponseData, GetBlobInfoResponseData, BlobReadOptions, CreateContextAliasRequest, CreateApplicationAliasRequest, CreateDeviceAliasRequest, CreateAliasResponseData, LookupAliasResponseData, DeleteAliasResponseData, ListAliasesResponseData, ListNamespacesResponseData, CreateNamespaceRequest, CreateNamespaceResponseData, DeleteNamespaceResponseData, CreateNamespaceInvitationRequest, CreateNamespaceInvitationResponseData, CreateRecursiveInvitationResponseData, JoinNamespaceRequest, JoinNamespaceResponseData, CreateGroupInNamespaceRequest, CreateGroupInNamespaceResponseData, SubgroupEntry, Namespace, NamespaceIdentity, NodeIdentity, AccountPairInitRequest, AccountPairInitResponseData, AccountPairCompleteRequest, AccountPairCompleteResponseData, AccountSignWithRootRequest, AccountSignWithRootResponseData, RelinkDeviceRequest, RelinkDeviceResponseData, RescopeDeviceRequest, RescopeDeviceResponseData, LabelDeviceRequest, LabelDeviceResponseData, AccountDeviceEntry, AccountApplicationEntry, RevokeAccountDeviceRequest, RevokeAccountDeviceResponseData, MemberDevicesEntry, ListMemberDevicesOptions, GroupInfoResponseData, CreateGroupRequest, CreateGroupResponseData, DeleteGroupResponseData, ListGroupMembersResponseData, ListGroupContextsResponseData, AddGroupMembersRequest, RemoveGroupMembersRequest, UpdateMemberRoleRequest, MemberCapabilities, SetMemberCapabilitiesRequest, SetDefaultCapabilitiesRequest, SetMemberAutoFollowRequest, SetSubgroupVisibilityRequest, SetTeeAdmissionPolicyRequest, GetTeeAdmissionPolicyResponseData, SetTeeAuthoringPolicyRequest, SetGroupMetadataRequest, SetMemberMetadataRequest, SetContextMetadataRequest, MetadataRecord, SyncGroupResponseData, UpgradeGroupRequest, UpgradeGroupResponseData, GroupUpgradeStatusResponseData, MigrationStatus, CascadeStatusEntry, RetryGroupUpgradeResponseData, ReparentGroupRequest, ReparentGroupResponseData, IssueOwnershipProofRequest, IssueNamespaceOwnershipProofRequest, IssueOwnershipProofResponseData, CreateGroupInvitationRequest, CreateGroupInvitationResponseData, CreateRecursiveGroupInvitationResponseData, JoinGroupRequest, JoinGroupResponseData, TeeInfoResponseData, TeeAttestRequest, TeeAttestResponseData, TeeVerifyQuoteRequest, TeeVerifyQuoteResponseData, PerformIntentRequest, PerformIntentResponseData, IntentRelayInfo, QueryContextRequest, QueryContextResponseData, ListMemberDevicesResponseData, SealToAccountRequest, SealedEnvelope, AdmitJoinRequest, AdmitJoinResponseData, WarrantNonceState } from './admin-types.js';
|
|
2
|
+
import type { HealthStatus, ReadinessStatus, AdminAuthStatus, InstallApplicationRequest, InstallApplicationResponseData, InstallDevApplicationRequest, UninstallApplicationResponseData, ListApplicationsResponseData, GetApplicationResponseData, ApplicationVersionEntry, GetApplicationAbiResponseData, GetLatestVersionResponseData, ListPackagesResponseData, ListVersionsResponseData, CreateContextRequest, CreateContextResponseData, DeleteContextResponseData, GetContextsResponseData, Context, GenerateContextIdentityResponseData, GetContextIdentitiesResponseData, JoinContextResponseData, JoinSubgroupInheritanceResponseData, ContextGroupResponseData, ContextStorageResponseData, InviteSpecializedNodeRequest, InviteSpecializedNodeResponseData, UpdateContextApplicationRequest, ResyncContextRequest, ResyncContextResponseData, ContextsWithExecutorsResponseData, UploadBlobRequest, UploadBlobResponseData, DeleteBlobResponseData, ListBlobsResponseData, GetBlobInfoResponseData, BlobReadOptions, CreateContextAliasRequest, CreateApplicationAliasRequest, CreateDeviceAliasRequest, CreateAliasResponseData, LookupAliasResponseData, DeleteAliasResponseData, ListAliasesResponseData, ListNamespacesResponseData, CreateNamespaceRequest, CreateNamespaceResponseData, DeleteNamespaceResponseData, CreateNamespaceInvitationRequest, CreateNamespaceInvitationResponseData, CreateRecursiveInvitationResponseData, JoinNamespaceRequest, JoinNamespaceResponseData, CreateGroupInNamespaceRequest, CreateGroupInNamespaceResponseData, SubgroupEntry, Namespace, NamespaceIdentity, NodeIdentity, AccountPairInitRequest, AccountPairInitResponseData, AccountPairCompleteRequest, AccountPairCompleteResponseData, AccountSignWithRootRequest, AccountSignWithRootResponseData, RelinkDeviceRequest, RelinkDeviceResponseData, RescopeDeviceRequest, RescopeDeviceResponseData, LabelDeviceRequest, LabelDeviceResponseData, AccountDeviceEntry, AccountApplicationEntry, RevokeAccountDeviceRequest, LinkAccountDeviceRequest, LinkAccountDeviceResponseData, RevokeAccountDeviceResponseData, MemberDevicesEntry, ListMemberDevicesOptions, GroupInfoResponseData, CreateGroupRequest, CreateGroupResponseData, DeleteGroupResponseData, ListGroupMembersResponseData, ListGroupContextsResponseData, AddGroupMembersRequest, RemoveGroupMembersRequest, UpdateMemberRoleRequest, MemberCapabilities, SetMemberCapabilitiesRequest, SetDefaultCapabilitiesRequest, SetMemberAutoFollowRequest, SetSubgroupVisibilityRequest, SetTeeAdmissionPolicyRequest, GetTeeAdmissionPolicyResponseData, SetTeeAuthoringPolicyRequest, SetGroupMetadataRequest, SetMemberMetadataRequest, SetContextMetadataRequest, MetadataRecord, SyncGroupResponseData, UpgradeGroupRequest, UpgradeGroupResponseData, GroupUpgradeStatusResponseData, MigrationStatus, CascadeStatusEntry, RetryGroupUpgradeResponseData, ReparentGroupRequest, ReparentGroupResponseData, IssueOwnershipProofRequest, IssueNamespaceOwnershipProofRequest, IssueOwnershipProofResponseData, CreateGroupInvitationRequest, CreateGroupInvitationResponseData, CreateRecursiveGroupInvitationResponseData, JoinGroupRequest, JoinGroupResponseData, TeeInfoResponseData, TeeAttestRequest, TeeAttestResponseData, TeeVerifyQuoteRequest, TeeVerifyQuoteResponseData, PerformIntentRequest, PerformIntentResponseData, IntentRelayInfo, QueryContextRequest, QueryContextResponseData, ListMemberDevicesResponseData, SealToAccountRequest, SealedEnvelope, AdmitJoinRequest, AdmitJoinResponseData, WarrantNonceState } from './admin-types.js';
|
|
3
3
|
import { type RedeemOutcome } from './redeem-invitation.js';
|
|
4
4
|
/**
|
|
5
5
|
* Thrown when a node answers the warrant-nonce route with a 404.
|
|
@@ -437,6 +437,22 @@ export declare class AdminApiClient {
|
|
|
437
437
|
* that - "this device can no longer act" is the only claim it supports.
|
|
438
438
|
*/
|
|
439
439
|
revokeAccountDevice(namespaceId: string, request: RevokeAccountDeviceRequest): Promise<RevokeAccountDeviceResponseData>;
|
|
440
|
+
/**
|
|
441
|
+
* Carry the device link of an account **this node does not hold**, so the
|
|
442
|
+
* namespace binds that device's key to the account.
|
|
443
|
+
*
|
|
444
|
+
* The relay half of a nodeless account minting invitations. An account added
|
|
445
|
+
* to a group by account holds its grants but has no device bound, so peers
|
|
446
|
+
* refuse whatever its device signs as "bound to no account". The credential
|
|
447
|
+
* and scope are root-signed and self-certifying; this node adds its own
|
|
448
|
+
* member endorsement and publishes the `AccountDeviceLinked`. After that the
|
|
449
|
+
* device signs invitations itself — see `signGroupInvitation`.
|
|
450
|
+
*
|
|
451
|
+
* Refusals: `400` when a proof does not verify or the scope does not reach
|
|
452
|
+
* this namespace (re-sign it), `403` when the device was revoked here or the
|
|
453
|
+
* account is a member of nothing in the namespace (add it first).
|
|
454
|
+
*/
|
|
455
|
+
linkAccountDevice(namespaceId: string, request: LinkAccountDeviceRequest): Promise<LinkAccountDeviceResponseData>;
|
|
440
456
|
getGroupInfo(groupId: string): Promise<GroupInfoResponseData>;
|
|
441
457
|
/** Thin wrapper over {@link getGroupInfo}: returns the group's `defaultCapabilities` bitmask. */
|
|
442
458
|
getDefaultCapabilities(groupId: string): Promise<number>;
|
|
@@ -829,6 +829,24 @@ export class AdminApiClient {
|
|
|
829
829
|
async revokeAccountDevice(namespaceId, request) {
|
|
830
830
|
return unwrap(await this.httpClient.post(`/admin-api/namespaces/${namespaceId}/account/revoke`, request));
|
|
831
831
|
}
|
|
832
|
+
/**
|
|
833
|
+
* Carry the device link of an account **this node does not hold**, so the
|
|
834
|
+
* namespace binds that device's key to the account.
|
|
835
|
+
*
|
|
836
|
+
* The relay half of a nodeless account minting invitations. An account added
|
|
837
|
+
* to a group by account holds its grants but has no device bound, so peers
|
|
838
|
+
* refuse whatever its device signs as "bound to no account". The credential
|
|
839
|
+
* and scope are root-signed and self-certifying; this node adds its own
|
|
840
|
+
* member endorsement and publishes the `AccountDeviceLinked`. After that the
|
|
841
|
+
* device signs invitations itself — see `signGroupInvitation`.
|
|
842
|
+
*
|
|
843
|
+
* Refusals: `400` when a proof does not verify or the scope does not reach
|
|
844
|
+
* this namespace (re-sign it), `403` when the device was revoked here or the
|
|
845
|
+
* account is a member of nothing in the namespace (add it first).
|
|
846
|
+
*/
|
|
847
|
+
async linkAccountDevice(namespaceId, request) {
|
|
848
|
+
return unwrap(await this.httpClient.post(`/admin-api/namespaces/${namespaceId}/account/link-device`, request));
|
|
849
|
+
}
|
|
832
850
|
// ---- Group Management ----
|
|
833
851
|
async getGroupInfo(groupId) {
|
|
834
852
|
return unwrap(await this.httpClient.get(`/admin-api/groups/${groupId}`));
|
|
@@ -1162,6 +1162,40 @@ export interface RevokeAccountDeviceResponseData {
|
|
|
1162
1162
|
*/
|
|
1163
1163
|
revokedIn: RevocationOutcome[];
|
|
1164
1164
|
}
|
|
1165
|
+
/**
|
|
1166
|
+
* Bind a device of an account the node does not hold, so what that device
|
|
1167
|
+
* signs in the namespace resolves to its account.
|
|
1168
|
+
*
|
|
1169
|
+
* For an account with **no node**: its root certifies a device offline
|
|
1170
|
+
* (`signDeviceCert`) and scopes it
|
|
1171
|
+
* (`signDeviceScope`), and a relay that is a member of the namespace carries
|
|
1172
|
+
* the link, endorsing the account with its own member key. Both proofs are
|
|
1173
|
+
* root-signed, so the relay can carry them and cannot alter them.
|
|
1174
|
+
*/
|
|
1175
|
+
export interface LinkAccountDeviceRequest {
|
|
1176
|
+
/**
|
|
1177
|
+
* The device's credential: hex, borsh `AccountProof<DeviceCert>` — what
|
|
1178
|
+
* `signDeviceCert` returns and `merod account sign-cert` prints.
|
|
1179
|
+
*/
|
|
1180
|
+
credential: string;
|
|
1181
|
+
/**
|
|
1182
|
+
* The device's scope: hex, borsh `AccountProof<DeviceScope>` — what
|
|
1183
|
+
* `signDeviceScope` returns. It must reach the namespace's application, or
|
|
1184
|
+
* name none.
|
|
1185
|
+
*/
|
|
1186
|
+
scope: string;
|
|
1187
|
+
}
|
|
1188
|
+
export interface LinkAccountDeviceResponseData {
|
|
1189
|
+
/** The account the device speaks for, 64 hex. */
|
|
1190
|
+
accountId: string;
|
|
1191
|
+
/** The device now bound, 64 hex. */
|
|
1192
|
+
deviceId: string;
|
|
1193
|
+
/**
|
|
1194
|
+
* The namespace already bound this device key, so nothing was published.
|
|
1195
|
+
* A repeat call is harmless and answers `true`.
|
|
1196
|
+
*/
|
|
1197
|
+
alreadyBound: boolean;
|
|
1198
|
+
}
|
|
1165
1199
|
/** One device of one member account, as the group's live bindings record it. */
|
|
1166
1200
|
export interface MemberDeviceEntry {
|
|
1167
1201
|
/** The device id, 64 hex - the form {@link RevokeAccountDeviceRequest.deviceId} takes. */
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { type Signer } from '../signer/signer.js';
|
|
2
|
+
/**
|
|
3
|
+
* Core's `ACCOUNT_GENESIS_VERSION`. It is part of the `AccountId` preimage, so
|
|
4
|
+
* this value decides which account a root key names — a mismatch does not fail
|
|
5
|
+
* as a version error at the edge, it silently derives a different account and
|
|
6
|
+
* core refuses the credential as unverifiable.
|
|
7
|
+
*
|
|
8
|
+
* `2` since the genesis dropped its per-namespace nonce. This was `1`, which
|
|
9
|
+
* produced credentials current core rejects outright; the shape was already v2,
|
|
10
|
+
* only the tag was stale.
|
|
11
|
+
*/
|
|
12
|
+
export declare const ACCOUNT_GENESIS_VERSION = 2;
|
|
2
13
|
/** What a root certifies about one device. */
|
|
3
14
|
export interface DeviceCertInput {
|
|
4
15
|
/**
|
|
@@ -20,7 +20,6 @@ import { resolveSigner } from '../signer/signer.js';
|
|
|
20
20
|
const CERT_DOMAIN = new TextEncoder().encode('calimero.device.cert.v1');
|
|
21
21
|
const ACCOUNT_ID_DOMAIN = new TextEncoder().encode('calimero.account.genesis.v1');
|
|
22
22
|
const DEVICE_ID_DOMAIN = new TextEncoder().encode('calimero.device.id.v1');
|
|
23
|
-
/** `AccountGenesis::version`, which the credential's borsh encoding leads with. */
|
|
24
23
|
/**
|
|
25
24
|
* Core's `ACCOUNT_GENESIS_VERSION`. It is part of the `AccountId` preimage, so
|
|
26
25
|
* this value decides which account a root key names — a mismatch does not fail
|
|
@@ -31,7 +30,7 @@ const DEVICE_ID_DOMAIN = new TextEncoder().encode('calimero.device.id.v1');
|
|
|
31
30
|
* produced credentials current core rejects outright; the shape was already v2,
|
|
32
31
|
* only the tag was stale.
|
|
33
32
|
*/
|
|
34
|
-
const ACCOUNT_GENESIS_VERSION = 2;
|
|
33
|
+
export const ACCOUNT_GENESIS_VERSION = 2;
|
|
35
34
|
/** Byte length of an `AccountProof<DeviceCert>` with an empty handoff chain. */
|
|
36
35
|
const ACCOUNT_PROOF_BYTES = 237;
|
|
37
36
|
/**
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type Signer } from '../signer/signer.js';
|
|
2
|
+
/** What a root scopes one device to. */
|
|
3
|
+
export interface DeviceScopeInput {
|
|
4
|
+
/**
|
|
5
|
+
* The account root's signing secret, 64 hex. Pass this or {@link signer}.
|
|
6
|
+
*/
|
|
7
|
+
rootSecret?: string;
|
|
8
|
+
/**
|
|
9
|
+
* The account root as a {@link Signer} — for a root that cannot be exported.
|
|
10
|
+
* Its `publicKey` is the genesis key the proof carries, and the account is
|
|
11
|
+
* derived from it.
|
|
12
|
+
*/
|
|
13
|
+
signer?: Signer;
|
|
14
|
+
/** The device being scoped, 64 hex — the one its certificate names. */
|
|
15
|
+
device: string;
|
|
16
|
+
/**
|
|
17
|
+
* Application ids the device may speak for, 64 hex each. **Empty means all of
|
|
18
|
+
* them**, which is also what the default is.
|
|
19
|
+
*
|
|
20
|
+
* A namespace binds the device only when its application is listed here (or
|
|
21
|
+
* the list is empty), so a scope naming the wrong application yields a relay
|
|
22
|
+
* refusal of `400`, not a binding.
|
|
23
|
+
*/
|
|
24
|
+
applications?: readonly string[];
|
|
25
|
+
/**
|
|
26
|
+
* Orders scopes for this device: only a higher one supersedes. 0 for a
|
|
27
|
+
* device's first scope.
|
|
28
|
+
*/
|
|
29
|
+
scopeEpoch?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The 32 bytes a root signs to scope a device: `domain_hash` over account,
|
|
33
|
+
* device, `scope_epoch` (u32 LE), `key_epoch` (u32 LE), then each application id
|
|
34
|
+
* as its own length-prefixed part.
|
|
35
|
+
*/
|
|
36
|
+
export declare function deviceScopePayload(input: {
|
|
37
|
+
account: string;
|
|
38
|
+
device: string;
|
|
39
|
+
applications: readonly string[];
|
|
40
|
+
scopeEpoch: number;
|
|
41
|
+
keyEpoch: number;
|
|
42
|
+
}): Promise<Uint8Array>;
|
|
43
|
+
/**
|
|
44
|
+
* Scope a device, returning the hex `AccountProof<DeviceScope>` a relay's
|
|
45
|
+
* `linkAccountDevice` takes beside the credential.
|
|
46
|
+
*
|
|
47
|
+
* ```
|
|
48
|
+
* AccountProof { genesis: AccountGenesis, chain: Vec<RootKeyHandoff>, statement: DeviceScope }
|
|
49
|
+
* AccountGenesis { version: u8, root_sign_pk: [u8; 32] }
|
|
50
|
+
* chain → u32-LE count (0 here)
|
|
51
|
+
* DeviceScope { account, device: [u8; 32] x2, applications: Vec<[u8; 32]>,
|
|
52
|
+
* scope_epoch: u32, key_epoch: u32, signature: [u8; 64] }
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* `chain` is empty and `key_epoch` 0 for the reason they are in
|
|
56
|
+
* {@link signDeviceCert}: a root that was never handed off signs directly.
|
|
57
|
+
*/
|
|
58
|
+
export declare function signDeviceScope(input: DeviceScopeInput): Promise<string>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scoping a device offline: which applications a device of an account may speak
|
|
3
|
+
* for, signed by the account root.
|
|
4
|
+
*
|
|
5
|
+
* The certificate from {@link signDeviceCert} says *this key is a device of the
|
|
6
|
+
* account*. It does not say where: that is this statement, and a namespace binds
|
|
7
|
+
* a device only when both arrive together. A node that pairs a device signs the
|
|
8
|
+
* scope for you; an account with **no node** has to sign it itself, next to the
|
|
9
|
+
* certificate, and hand both to a relay's `linkAccountDevice`.
|
|
10
|
+
*
|
|
11
|
+
* Derived from core:
|
|
12
|
+
*
|
|
13
|
+
* - `DeviceScope` and `DeviceScope::signing_payload` — `crates/account/src/scope.rs`
|
|
14
|
+
* - `DEVICE_SCOPE_SIGN_DOMAIN` — `crates/account/src/domain.rs`
|
|
15
|
+
* - `AccountProof` / `AccountGenesis` borsh layout — `crates/account/src/{signed,account}.rs`
|
|
16
|
+
*
|
|
17
|
+
* The unit tests pin vectors produced by core's own `DeviceScope::sign`.
|
|
18
|
+
*/
|
|
19
|
+
import { concat, domainHash, fromHex, hex, u32le } from '../crypto/internal.js';
|
|
20
|
+
import { resolveSigner } from '../signer/signer.js';
|
|
21
|
+
import { accountForRootPublicKey, ACCOUNT_GENESIS_VERSION } from './device-cert.js';
|
|
22
|
+
const SCOPE_DOMAIN = new TextEncoder().encode('calimero.device.scope.v1');
|
|
23
|
+
/**
|
|
24
|
+
* The 32 bytes a root signs to scope a device: `domain_hash` over account,
|
|
25
|
+
* device, `scope_epoch` (u32 LE), `key_epoch` (u32 LE), then each application id
|
|
26
|
+
* as its own length-prefixed part.
|
|
27
|
+
*/
|
|
28
|
+
export async function deviceScopePayload(input) {
|
|
29
|
+
return domainHash(SCOPE_DOMAIN, [
|
|
30
|
+
fromHex(input.account, 'account', 32),
|
|
31
|
+
fromHex(input.device, 'device', 32),
|
|
32
|
+
u32le(input.scopeEpoch),
|
|
33
|
+
u32le(input.keyEpoch),
|
|
34
|
+
...input.applications.map((a, i) => fromHex(a, `applications[${i}]`, 32)),
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Scope a device, returning the hex `AccountProof<DeviceScope>` a relay's
|
|
39
|
+
* `linkAccountDevice` takes beside the credential.
|
|
40
|
+
*
|
|
41
|
+
* ```
|
|
42
|
+
* AccountProof { genesis: AccountGenesis, chain: Vec<RootKeyHandoff>, statement: DeviceScope }
|
|
43
|
+
* AccountGenesis { version: u8, root_sign_pk: [u8; 32] }
|
|
44
|
+
* chain → u32-LE count (0 here)
|
|
45
|
+
* DeviceScope { account, device: [u8; 32] x2, applications: Vec<[u8; 32]>,
|
|
46
|
+
* scope_epoch: u32, key_epoch: u32, signature: [u8; 64] }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* `chain` is empty and `key_epoch` 0 for the reason they are in
|
|
50
|
+
* {@link signDeviceCert}: a root that was never handed off signs directly.
|
|
51
|
+
*/
|
|
52
|
+
export async function signDeviceScope(input) {
|
|
53
|
+
const signer = await resolveSigner(input.rootSecret, input.signer, 'rootSecret');
|
|
54
|
+
const rootPublicKey = fromHex(signer.publicKey, 'signer.publicKey', 32);
|
|
55
|
+
const account = await accountForRootPublicKey(hex(rootPublicKey));
|
|
56
|
+
const applications = input.applications ?? [];
|
|
57
|
+
const scopeEpoch = input.scopeEpoch ?? 0;
|
|
58
|
+
// `u32le` would wrap a negative or oversized value into a different epoch
|
|
59
|
+
// rather than refuse it, and the scope would then order itself wrongly.
|
|
60
|
+
if (!Number.isInteger(scopeEpoch) || scopeEpoch < 0 || scopeEpoch > 4294967295) {
|
|
61
|
+
throw new Error(`scopeEpoch must be a u32, got ${scopeEpoch}`);
|
|
62
|
+
}
|
|
63
|
+
const keyEpoch = 0;
|
|
64
|
+
const payload = await deviceScopePayload({
|
|
65
|
+
account,
|
|
66
|
+
device: input.device,
|
|
67
|
+
applications,
|
|
68
|
+
scopeEpoch,
|
|
69
|
+
keyEpoch,
|
|
70
|
+
});
|
|
71
|
+
const signature = await signer.sign(payload);
|
|
72
|
+
if (signature.length !== 64) {
|
|
73
|
+
throw new Error(`signer returned ${signature.length} bytes, expected a 64-byte Ed25519 signature`);
|
|
74
|
+
}
|
|
75
|
+
return hex(concat(new Uint8Array([ACCOUNT_GENESIS_VERSION]), rootPublicKey, u32le(0), fromHex(account, 'account', 32), fromHex(input.device, 'device', 32), u32le(applications.length), ...applications.map((a, i) => fromHex(a, `applications[${i}]`, 32)), u32le(scopeEpoch), u32le(keyEpoch), signature));
|
|
76
|
+
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { signDeviceCert, mintDeviceId, deviceCertPayload, accountForRoot, accountForRootPublicKey, accountProofBytes, parseDeviceCredential, verifyDeviceCredential, } from './device-cert.js';
|
|
2
2
|
export type { DeviceCertInput, DeviceCredential } from './device-cert.js';
|
|
3
|
+
export { signDeviceScope, deviceScopePayload } from './device-scope.js';
|
|
4
|
+
export type { DeviceScopeInput } from './device-scope.js';
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
// Offline device certification — the account-root half of the keyholder story.
|
|
2
2
|
export { signDeviceCert, mintDeviceId, deviceCertPayload, accountForRoot, accountForRootPublicKey, accountProofBytes, parseDeviceCredential, verifyDeviceCredential, } from './device-cert.js';
|
|
3
|
+
export { signDeviceScope, deviceScopePayload } from './device-scope.js';
|