@ipab/cli 0.1.0-rc.13 → 0.1.0-rc.14
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/builtins/skill.ipab.car +0 -0
- package/dist/swarm.d.ts.map +1 -1
- package/dist/swarm.js +17 -20
- package/dist/swarm.js.map +1 -1
- package/package.json +1 -1
- package/src/swarm.ts +29 -33
package/package.json
CHANGED
package/src/swarm.ts
CHANGED
|
@@ -3410,7 +3410,7 @@ export async function writeNamesHead(
|
|
|
3410
3410
|
return head.write(root, cid, uniqueId());
|
|
3411
3411
|
}
|
|
3412
3412
|
const idempotencyKey = uniqueId();
|
|
3413
|
-
let receipt: ScopeWriteReceipt
|
|
3413
|
+
let receipt: ScopeWriteReceipt;
|
|
3414
3414
|
try {
|
|
3415
3415
|
receipt = await requestPivotWriteReceipt(
|
|
3416
3416
|
context,
|
|
@@ -3427,9 +3427,6 @@ export async function writeNamesHead(
|
|
|
3427
3427
|
"publication",
|
|
3428
3428
|
);
|
|
3429
3429
|
}
|
|
3430
|
-
if (receipt === null) {
|
|
3431
|
-
return head.write(root, cid, idempotencyKey);
|
|
3432
|
-
}
|
|
3433
3430
|
return head.writeWithReceipt(receipt);
|
|
3434
3431
|
});
|
|
3435
3432
|
}
|
|
@@ -3440,7 +3437,7 @@ async function requestPivotWriteReceipt(
|
|
|
3440
3437
|
root: string,
|
|
3441
3438
|
ifCid: string,
|
|
3442
3439
|
idempotencyKey: string,
|
|
3443
|
-
): Promise<ScopeWriteReceipt
|
|
3440
|
+
): Promise<ScopeWriteReceipt> {
|
|
3444
3441
|
const record = await approvedMembership(context, url);
|
|
3445
3442
|
const config = record.config!;
|
|
3446
3443
|
const identity = await contextIdentity(context);
|
|
@@ -3450,26 +3447,21 @@ async function requestPivotWriteReceipt(
|
|
|
3450
3447
|
);
|
|
3451
3448
|
if (!pivots.length)
|
|
3452
3449
|
throw new HostError(
|
|
3453
|
-
"No Pivot nodes are declared. Declare an
|
|
3450
|
+
"No Pivot nodes are declared. Declare an authorized Pivot with swarm profile --pivot true before publishing; HEAD was not changed.",
|
|
3454
3451
|
);
|
|
3452
|
+
const self = pivots.find(
|
|
3453
|
+
({ member }) =>
|
|
3454
|
+
member.publicKey === record.account &&
|
|
3455
|
+
(record.account === config.owner ||
|
|
3456
|
+
record.secret?.certificate.body.write.includes(config.headId)),
|
|
3457
|
+
);
|
|
3455
3458
|
const remote = pivots.filter(
|
|
3456
3459
|
({ member }) => member.publicKey !== record.account,
|
|
3457
3460
|
);
|
|
3458
|
-
if (!remote.length)
|
|
3459
|
-
if (
|
|
3460
|
-
members.length === 1 &&
|
|
3461
|
-
members[0]!.member.publicKey === record.account &&
|
|
3462
|
-
record.account === config.owner
|
|
3463
|
-
) {
|
|
3464
|
-
context.diagnostic?.(
|
|
3465
|
-
`[${url}] Solo self-Pivot Swarm detected; publishing ${root} directly without remote Pivot receipt.`,
|
|
3466
|
-
);
|
|
3467
|
-
return null;
|
|
3468
|
-
}
|
|
3461
|
+
if (!self && !remote.length)
|
|
3469
3462
|
throw new HostError(
|
|
3470
|
-
"Publication requires an
|
|
3463
|
+
"Publication requires an authorized Pivot. Ask the Owner to grant Pivot HEAD authority; HEAD was not changed.",
|
|
3471
3464
|
);
|
|
3472
|
-
}
|
|
3473
3465
|
const authorized = remote.filter(
|
|
3474
3466
|
({ member }) =>
|
|
3475
3467
|
member.publicKey === config.owner ||
|
|
@@ -3477,7 +3469,7 @@ async function requestPivotWriteReceipt(
|
|
|
3477
3469
|
? member.role === "pivot"
|
|
3478
3470
|
: member.pivotAuthority === true),
|
|
3479
3471
|
);
|
|
3480
|
-
const
|
|
3472
|
+
const remoteCandidates = authorized.length
|
|
3481
3473
|
? [
|
|
3482
3474
|
...authorized,
|
|
3483
3475
|
...remote.filter(
|
|
@@ -3488,6 +3480,7 @@ async function requestPivotWriteReceipt(
|
|
|
3488
3480
|
),
|
|
3489
3481
|
]
|
|
3490
3482
|
: remote;
|
|
3483
|
+
const candidates = self ? [self, ...remoteCandidates] : remoteCandidates;
|
|
3491
3484
|
if (!context.requestPivotReceipt && !context.node)
|
|
3492
3485
|
throw new HostError("State pin requires an active publishing node.");
|
|
3493
3486
|
const c = coordinates(url);
|
|
@@ -3513,16 +3506,19 @@ async function requestPivotWriteReceipt(
|
|
|
3513
3506
|
const errors: string[] = [];
|
|
3514
3507
|
for (const pivot of candidates) {
|
|
3515
3508
|
try {
|
|
3516
|
-
const
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3509
|
+
const local = pivot === self;
|
|
3510
|
+
const receipt = local
|
|
3511
|
+
? await handlePivotReceiptRequest(context, url, request, signal)
|
|
3512
|
+
: context.requestPivotReceipt
|
|
3513
|
+
? await context.requestPivotReceipt(pivot, request, signal)
|
|
3514
|
+
: await requestPivotReceiptOverP2p(
|
|
3515
|
+
context.node!,
|
|
3516
|
+
pivot.member.peerId,
|
|
3517
|
+
pivot.profile.addresses,
|
|
3518
|
+
request,
|
|
3519
|
+
signal,
|
|
3520
|
+
context.fetch,
|
|
3521
|
+
);
|
|
3526
3522
|
if (
|
|
3527
3523
|
JSON.stringify(receipt.value) !== JSON.stringify({ root }) ||
|
|
3528
3524
|
receipt.ifCid !== ifCid ||
|
|
@@ -3533,7 +3529,7 @@ async function requestPivotWriteReceipt(
|
|
|
3533
3529
|
`Pivot ${pivot.member.publicKey} returned a receipt that does not match this publication.`,
|
|
3534
3530
|
);
|
|
3535
3531
|
context.diagnostic?.(
|
|
3536
|
-
`[${url}] Received HEAD write receipt from Pivot ${pivot.profile.name} (${pivot.member.publicKey}).`,
|
|
3532
|
+
`[${url}] Received HEAD write receipt from ${local ? "local" : "remote"} Pivot ${pivot.profile.name} (${pivot.member.publicKey})${local ? "; no independent replica is confirmed" : ""}.`,
|
|
3537
3533
|
);
|
|
3538
3534
|
return receipt;
|
|
3539
3535
|
} catch (cause) {
|
|
@@ -3545,7 +3541,7 @@ async function requestPivotWriteReceipt(
|
|
|
3545
3541
|
}
|
|
3546
3542
|
}
|
|
3547
3543
|
throw new HostError(
|
|
3548
|
-
`No authorized
|
|
3544
|
+
`No authorized Pivot issued a HEAD write receipt for publication ${root} (${errors.join("; ")}); HEAD was not changed.`,
|
|
3549
3545
|
);
|
|
3550
3546
|
}
|
|
3551
3547
|
|
|
@@ -3608,7 +3604,7 @@ export async function handlePivotReceiptRequest(
|
|
|
3608
3604
|
);
|
|
3609
3605
|
try {
|
|
3610
3606
|
if (CID.parse(request.root).code === dagPb.code) {
|
|
3611
|
-
if (peers.length > 0)
|
|
3607
|
+
if (peers.length > 0 && member.peerId !== node.peerId)
|
|
3612
3608
|
await probePeer(node, member.peerId, peers, signal).catch(() => false);
|
|
3613
3609
|
await readSnapshot(source, request.root, url);
|
|
3614
3610
|
await pinPublication(source, [request.root], node, signal, context.fetch);
|