@cofhe/sdk 1.0.0 → 1.1.0-alpha.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/core/acps.ts +64 -23
- package/core/client.ts +32 -1
- package/core/clientTypes.ts +22 -1
- package/core/test/acpsPrepare.test.ts +77 -0
- package/dist/acps.d.cts +4 -358
- package/dist/acps.d.ts +4 -358
- package/dist/{chunk-O2ITEUEU.js → chunk-2EO4JSR7.js} +63 -21
- package/dist/{clientTypes-b1pOxOUE.d.ts → clientTypes-CnslFzxB.d.ts} +38 -2
- package/dist/{clientTypes-IO6b5Um8.d.cts → clientTypes-RXwLVWou.d.cts} +38 -2
- package/dist/core.cjs +62 -20
- package/dist/core.d.cts +3 -3
- package/dist/core.d.ts +3 -3
- package/dist/core.js +1 -1
- package/dist/node.cjs +62 -20
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +1 -1
- package/dist/{onchain-utils-CgOslubH.d.ts → onchain-utils-Ns56cBm0.d.cts} +356 -2
- package/dist/{onchain-utils-CgOslubH.d.cts → onchain-utils-Ns56cBm0.d.ts} +356 -2
- package/dist/web.cjs +62 -20
- package/dist/web.d.cts +2 -2
- package/dist/web.d.ts +2 -2
- package/dist/web.js +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Hex, Address, PublicClient, WalletClient } from 'viem';
|
|
1
|
+
import { Hex, Address, PublicClient, WalletClient, AbiParameterToPrimitiveType } from 'viem';
|
|
2
2
|
|
|
3
3
|
type EthEncryptedData = {
|
|
4
4
|
data: Uint8Array;
|
|
@@ -504,6 +504,360 @@ declare const ACPUtils: {
|
|
|
504
504
|
checkAccessOnChain: (acp: ACP, publicClient: PublicClient, handle?: bigint | Hex) => Promise<ACPAccessStatus>;
|
|
505
505
|
};
|
|
506
506
|
|
|
507
|
+
/**
|
|
508
|
+
* The on-chain sharing pieces: the share registry and revoker ABIs, the registry payload of a
|
|
509
|
+
* sharing ACP and its share id, and the read of a share from its `Shared` event. Exported so an
|
|
510
|
+
* app can send these writes through its own transaction path and still agree with the registry
|
|
511
|
+
* on ids.
|
|
512
|
+
*
|
|
513
|
+
* The registry is pointer-based: storage keeps a share header (issuer, expiration, recipient,
|
|
514
|
+
* revoker, and the block of its `Shared` event); the full payload and the metadata blob travel in
|
|
515
|
+
* that event. A reader takes headers from `sharesFor` / `getShare` and fetches the events with one
|
|
516
|
+
* single-block `getLogs` per block.
|
|
517
|
+
*/
|
|
518
|
+
declare const ACP_REVOKER_ABI: readonly [{
|
|
519
|
+
readonly name: "revokeSingle";
|
|
520
|
+
readonly type: "function";
|
|
521
|
+
readonly stateMutability: "nonpayable";
|
|
522
|
+
readonly inputs: readonly [{
|
|
523
|
+
readonly type: "uint256";
|
|
524
|
+
readonly name: "id";
|
|
525
|
+
}];
|
|
526
|
+
readonly outputs: readonly [];
|
|
527
|
+
}, {
|
|
528
|
+
readonly name: "revokeAllExisting";
|
|
529
|
+
readonly type: "function";
|
|
530
|
+
readonly stateMutability: "nonpayable";
|
|
531
|
+
readonly inputs: readonly [];
|
|
532
|
+
readonly outputs: readonly [];
|
|
533
|
+
}, {
|
|
534
|
+
readonly name: "disabled";
|
|
535
|
+
readonly type: "function";
|
|
536
|
+
readonly stateMutability: "view";
|
|
537
|
+
readonly inputs: readonly [{
|
|
538
|
+
readonly type: "address";
|
|
539
|
+
readonly name: "issuer";
|
|
540
|
+
}, {
|
|
541
|
+
readonly type: "uint256";
|
|
542
|
+
readonly name: "id";
|
|
543
|
+
}];
|
|
544
|
+
readonly outputs: readonly [{
|
|
545
|
+
readonly type: "bool";
|
|
546
|
+
}];
|
|
547
|
+
}];
|
|
548
|
+
declare const ACP_SHARE_REGISTRY_ABI: readonly [{
|
|
549
|
+
readonly name: "share";
|
|
550
|
+
readonly type: "function";
|
|
551
|
+
readonly stateMutability: "nonpayable";
|
|
552
|
+
readonly inputs: readonly [{
|
|
553
|
+
readonly type: "tuple";
|
|
554
|
+
readonly components: readonly [{
|
|
555
|
+
readonly type: "address";
|
|
556
|
+
readonly name: "issuer";
|
|
557
|
+
}, {
|
|
558
|
+
readonly type: "uint64";
|
|
559
|
+
readonly name: "expiration";
|
|
560
|
+
}, {
|
|
561
|
+
readonly type: "address";
|
|
562
|
+
readonly name: "recipient";
|
|
563
|
+
}, {
|
|
564
|
+
readonly type: "uint256";
|
|
565
|
+
readonly name: "revokerData";
|
|
566
|
+
}, {
|
|
567
|
+
readonly type: "address";
|
|
568
|
+
readonly name: "revokerContract";
|
|
569
|
+
}, {
|
|
570
|
+
readonly type: "uint8";
|
|
571
|
+
readonly name: "scope";
|
|
572
|
+
}, {
|
|
573
|
+
readonly type: "address[]";
|
|
574
|
+
readonly name: "contracts";
|
|
575
|
+
}, {
|
|
576
|
+
readonly type: "bytes32[]";
|
|
577
|
+
readonly name: "handles";
|
|
578
|
+
}, {
|
|
579
|
+
readonly type: "bytes32";
|
|
580
|
+
readonly name: "sealingKey";
|
|
581
|
+
}, {
|
|
582
|
+
readonly type: "bytes";
|
|
583
|
+
readonly name: "issuerSignature";
|
|
584
|
+
}, {
|
|
585
|
+
readonly type: "bytes";
|
|
586
|
+
readonly name: "recipientSignature";
|
|
587
|
+
}];
|
|
588
|
+
readonly name: "acp";
|
|
589
|
+
}, {
|
|
590
|
+
readonly type: "bytes";
|
|
591
|
+
readonly name: "metadata";
|
|
592
|
+
}];
|
|
593
|
+
readonly outputs: readonly [{
|
|
594
|
+
readonly type: "bytes32";
|
|
595
|
+
}];
|
|
596
|
+
}, {
|
|
597
|
+
readonly name: "removeShare";
|
|
598
|
+
readonly type: "function";
|
|
599
|
+
readonly stateMutability: "nonpayable";
|
|
600
|
+
readonly inputs: readonly [{
|
|
601
|
+
readonly type: "bytes32";
|
|
602
|
+
readonly name: "shareId";
|
|
603
|
+
}];
|
|
604
|
+
readonly outputs: readonly [];
|
|
605
|
+
}, {
|
|
606
|
+
readonly name: "sharesFor";
|
|
607
|
+
readonly type: "function";
|
|
608
|
+
readonly stateMutability: "view";
|
|
609
|
+
readonly inputs: readonly [{
|
|
610
|
+
readonly type: "address";
|
|
611
|
+
readonly name: "recipient";
|
|
612
|
+
}];
|
|
613
|
+
readonly outputs: readonly [{
|
|
614
|
+
readonly type: "bytes32[]";
|
|
615
|
+
readonly name: "shareIds";
|
|
616
|
+
}, {
|
|
617
|
+
readonly type: "tuple[]";
|
|
618
|
+
readonly components: readonly [{
|
|
619
|
+
readonly type: "address";
|
|
620
|
+
readonly name: "issuer";
|
|
621
|
+
}, {
|
|
622
|
+
readonly type: "uint64";
|
|
623
|
+
readonly name: "expiration";
|
|
624
|
+
}, {
|
|
625
|
+
readonly type: "address";
|
|
626
|
+
readonly name: "recipient";
|
|
627
|
+
}, {
|
|
628
|
+
readonly type: "uint64";
|
|
629
|
+
readonly name: "blockNumber";
|
|
630
|
+
}, {
|
|
631
|
+
readonly type: "address";
|
|
632
|
+
readonly name: "revokerContract";
|
|
633
|
+
}, {
|
|
634
|
+
readonly type: "uint256";
|
|
635
|
+
readonly name: "revokerData";
|
|
636
|
+
}];
|
|
637
|
+
readonly name: "headers";
|
|
638
|
+
}];
|
|
639
|
+
}, {
|
|
640
|
+
readonly name: "getShare";
|
|
641
|
+
readonly type: "function";
|
|
642
|
+
readonly stateMutability: "view";
|
|
643
|
+
readonly inputs: readonly [{
|
|
644
|
+
readonly type: "bytes32";
|
|
645
|
+
readonly name: "shareId";
|
|
646
|
+
}];
|
|
647
|
+
readonly outputs: readonly [{
|
|
648
|
+
readonly type: "tuple";
|
|
649
|
+
readonly components: readonly [{
|
|
650
|
+
readonly type: "address";
|
|
651
|
+
readonly name: "issuer";
|
|
652
|
+
}, {
|
|
653
|
+
readonly type: "uint64";
|
|
654
|
+
readonly name: "expiration";
|
|
655
|
+
}, {
|
|
656
|
+
readonly type: "address";
|
|
657
|
+
readonly name: "recipient";
|
|
658
|
+
}, {
|
|
659
|
+
readonly type: "uint64";
|
|
660
|
+
readonly name: "blockNumber";
|
|
661
|
+
}, {
|
|
662
|
+
readonly type: "address";
|
|
663
|
+
readonly name: "revokerContract";
|
|
664
|
+
}, {
|
|
665
|
+
readonly type: "uint256";
|
|
666
|
+
readonly name: "revokerData";
|
|
667
|
+
}];
|
|
668
|
+
}];
|
|
669
|
+
}, {
|
|
670
|
+
readonly name: "isShareValid";
|
|
671
|
+
readonly type: "function";
|
|
672
|
+
readonly stateMutability: "view";
|
|
673
|
+
readonly inputs: readonly [{
|
|
674
|
+
readonly type: "bytes32";
|
|
675
|
+
readonly name: "shareId";
|
|
676
|
+
}];
|
|
677
|
+
readonly outputs: readonly [{
|
|
678
|
+
readonly type: "bool";
|
|
679
|
+
}];
|
|
680
|
+
}, {
|
|
681
|
+
readonly name: "Shared";
|
|
682
|
+
readonly type: "event";
|
|
683
|
+
readonly inputs: readonly [{
|
|
684
|
+
readonly type: "address";
|
|
685
|
+
readonly name: "recipient";
|
|
686
|
+
readonly indexed: true;
|
|
687
|
+
}, {
|
|
688
|
+
readonly type: "address";
|
|
689
|
+
readonly name: "issuer";
|
|
690
|
+
readonly indexed: true;
|
|
691
|
+
}, {
|
|
692
|
+
readonly type: "bytes32";
|
|
693
|
+
readonly name: "shareId";
|
|
694
|
+
readonly indexed: true;
|
|
695
|
+
}, {
|
|
696
|
+
readonly type: "tuple";
|
|
697
|
+
readonly components: readonly [{
|
|
698
|
+
readonly type: "address";
|
|
699
|
+
readonly name: "issuer";
|
|
700
|
+
}, {
|
|
701
|
+
readonly type: "uint64";
|
|
702
|
+
readonly name: "expiration";
|
|
703
|
+
}, {
|
|
704
|
+
readonly type: "address";
|
|
705
|
+
readonly name: "recipient";
|
|
706
|
+
}, {
|
|
707
|
+
readonly type: "uint256";
|
|
708
|
+
readonly name: "revokerData";
|
|
709
|
+
}, {
|
|
710
|
+
readonly type: "address";
|
|
711
|
+
readonly name: "revokerContract";
|
|
712
|
+
}, {
|
|
713
|
+
readonly type: "uint8";
|
|
714
|
+
readonly name: "scope";
|
|
715
|
+
}, {
|
|
716
|
+
readonly type: "address[]";
|
|
717
|
+
readonly name: "contracts";
|
|
718
|
+
}, {
|
|
719
|
+
readonly type: "bytes32[]";
|
|
720
|
+
readonly name: "handles";
|
|
721
|
+
}, {
|
|
722
|
+
readonly type: "bytes32";
|
|
723
|
+
readonly name: "sealingKey";
|
|
724
|
+
}, {
|
|
725
|
+
readonly type: "bytes";
|
|
726
|
+
readonly name: "issuerSignature";
|
|
727
|
+
}, {
|
|
728
|
+
readonly type: "bytes";
|
|
729
|
+
readonly name: "recipientSignature";
|
|
730
|
+
}];
|
|
731
|
+
readonly name: "acp";
|
|
732
|
+
}, {
|
|
733
|
+
readonly type: "bytes";
|
|
734
|
+
readonly name: "metadata";
|
|
735
|
+
}];
|
|
736
|
+
}, {
|
|
737
|
+
readonly name: "ShareRemoved";
|
|
738
|
+
readonly type: "event";
|
|
739
|
+
readonly inputs: readonly [{
|
|
740
|
+
readonly type: "address";
|
|
741
|
+
readonly name: "recipient";
|
|
742
|
+
readonly indexed: true;
|
|
743
|
+
}, {
|
|
744
|
+
readonly type: "address";
|
|
745
|
+
readonly name: "issuer";
|
|
746
|
+
readonly indexed: true;
|
|
747
|
+
}, {
|
|
748
|
+
readonly type: "bytes32";
|
|
749
|
+
readonly name: "shareId";
|
|
750
|
+
readonly indexed: true;
|
|
751
|
+
}];
|
|
752
|
+
}];
|
|
753
|
+
declare const ACP_SHARE_TUPLE_ABI: readonly [{
|
|
754
|
+
readonly type: "tuple";
|
|
755
|
+
readonly components: readonly [{
|
|
756
|
+
readonly name: "issuer";
|
|
757
|
+
readonly type: "address";
|
|
758
|
+
}, {
|
|
759
|
+
readonly name: "expiration";
|
|
760
|
+
readonly type: "uint64";
|
|
761
|
+
}, {
|
|
762
|
+
readonly name: "recipient";
|
|
763
|
+
readonly type: "address";
|
|
764
|
+
}, {
|
|
765
|
+
readonly name: "revokerData";
|
|
766
|
+
readonly type: "uint256";
|
|
767
|
+
}, {
|
|
768
|
+
readonly name: "revokerContract";
|
|
769
|
+
readonly type: "address";
|
|
770
|
+
}, {
|
|
771
|
+
readonly name: "scope";
|
|
772
|
+
readonly type: "uint8";
|
|
773
|
+
}, {
|
|
774
|
+
readonly name: "contracts";
|
|
775
|
+
readonly type: "address[]";
|
|
776
|
+
}, {
|
|
777
|
+
readonly name: "handles";
|
|
778
|
+
readonly type: "bytes32[]";
|
|
779
|
+
}, {
|
|
780
|
+
readonly name: "sealingKey";
|
|
781
|
+
readonly type: "bytes32";
|
|
782
|
+
}, {
|
|
783
|
+
readonly name: "issuerSignature";
|
|
784
|
+
readonly type: "bytes";
|
|
785
|
+
}, {
|
|
786
|
+
readonly name: "recipientSignature";
|
|
787
|
+
readonly type: "bytes";
|
|
788
|
+
}];
|
|
789
|
+
}];
|
|
790
|
+
/** The on-chain payload for a sharing ACP: recipient-side fields empty. */
|
|
791
|
+
declare const toChainShare: (acp: ACP) => {
|
|
792
|
+
expiration: bigint;
|
|
793
|
+
revokerData: bigint;
|
|
794
|
+
sealingKey: `0x${string}`;
|
|
795
|
+
recipientSignature: Hex;
|
|
796
|
+
issuer: Hex;
|
|
797
|
+
recipient: Hex;
|
|
798
|
+
revokerContract: Hex;
|
|
799
|
+
scope: number;
|
|
800
|
+
contracts: Hex[];
|
|
801
|
+
handles: Hex[];
|
|
802
|
+
issuerSignature: Hex;
|
|
803
|
+
};
|
|
804
|
+
/** Mirrors the registry's `keccak256(abi.encode(acp))` share id. */
|
|
805
|
+
declare const computeShareId: (acp: ACP) => Hex;
|
|
806
|
+
/** The share id of a registry payload as read back from a `Shared` event. */
|
|
807
|
+
declare const shareIdOfChainShare: (share: ChainShare) => Hex;
|
|
808
|
+
/** A registry payload, as decoded from a `Shared` event (or passed to `share`). */
|
|
809
|
+
type ChainShare = AbiParameterToPrimitiveType<(typeof ACP_SHARE_TUPLE_ABI)[0]>;
|
|
810
|
+
/** What the registry stores of a share: the fields it checks, and the block of its `Shared` event. */
|
|
811
|
+
type ShareHeader = {
|
|
812
|
+
issuer: Address;
|
|
813
|
+
expiration: bigint;
|
|
814
|
+
recipient: Address;
|
|
815
|
+
/** Block of the `Shared` event (the L2 block on Arbitrum). */
|
|
816
|
+
blockNumber: bigint;
|
|
817
|
+
revokerContract: Address;
|
|
818
|
+
revokerData: bigint;
|
|
819
|
+
};
|
|
820
|
+
/** A share as posted: its payload and the metadata blob that came with it (`0x` when none). */
|
|
821
|
+
type PostedShare = {
|
|
822
|
+
shareId: Hex;
|
|
823
|
+
header: ShareHeader;
|
|
824
|
+
share: ChainShare;
|
|
825
|
+
metadata: Hex;
|
|
826
|
+
};
|
|
827
|
+
/** A share the registry lists but whose `Shared` event could not be read, and why. */
|
|
828
|
+
type UnreadableShare = {
|
|
829
|
+
shareId: Hex;
|
|
830
|
+
header: ShareHeader;
|
|
831
|
+
reason: string;
|
|
832
|
+
};
|
|
833
|
+
/** Shares read from their events, and those that could not be; each share is on its own. */
|
|
834
|
+
type PostedShares = {
|
|
835
|
+
posted: PostedShare[];
|
|
836
|
+
unreadable: UnreadableShare[];
|
|
837
|
+
};
|
|
838
|
+
/**
|
|
839
|
+
* Fetches the `Shared` events of shares from the blocks their headers name: one single-block
|
|
840
|
+
* `getLogs` per distinct block, filtered by registry and share ids, so any node answers it. Returns
|
|
841
|
+
* the shares in the order given; where a block holds several events for one share id, the last.
|
|
842
|
+
* Never fails as a whole: a share whose block the node cannot serve yet, whose event is missing
|
|
843
|
+
* from it, or whose event payload does not hash to its id is returned as `unreadable`, with the
|
|
844
|
+
* reason, and the rest are posted as usual.
|
|
845
|
+
*/
|
|
846
|
+
declare const readPostedShares: (publicClient: PublicClient, registry: Address, headers: readonly {
|
|
847
|
+
shareId: Hex;
|
|
848
|
+
header: ShareHeader;
|
|
849
|
+
}[]) => Promise<PostedShares>;
|
|
850
|
+
/**
|
|
851
|
+
* The importable shares addressed to `recipient` (unexpired, not revoked), read from their events;
|
|
852
|
+
* those whose event could not be read are listed apart, so one of them never hides the rest.
|
|
853
|
+
*/
|
|
854
|
+
declare const readSharesFor: (publicClient: PublicClient, registry: Address, recipient: Address) => Promise<PostedShares>;
|
|
855
|
+
/**
|
|
856
|
+
* One share by id, read from its event; null when the registry has no such share (unknown or
|
|
857
|
+
* removed). Throws, with the reason, when the registry lists it but its event could not be read.
|
|
858
|
+
*/
|
|
859
|
+
declare const readShare: (publicClient: PublicClient, registry: Address, shareId: Hex) => Promise<PostedShare | null>;
|
|
860
|
+
|
|
507
861
|
/**
|
|
508
862
|
* - `verified`: the chain confirms the label.
|
|
509
863
|
* - `mismatch`: the chain contradicts it.
|
|
@@ -558,4 +912,4 @@ declare const clearAclServedAddresses: () => void;
|
|
|
558
912
|
*/
|
|
559
913
|
declare const getAclServedAddresses: (publicClient: PublicClient, chainId: number) => Promise<AclServedAddresses>;
|
|
560
914
|
|
|
561
|
-
export { type ACP as A, type
|
|
915
|
+
export { type SelfACP as $, type ACP as A, type ChainShare as B, type CreateSelfACPOptions as C, type ShareHeader as D, type EventValueLabel as E, type PostedShares as F, GenerateSealingKey as G, readPostedShares as H, type ImportSharedACPOptions as I, readSharesFor as J, readShare as K, type LabelledShare as L, type ShareLabelReadArg as M, type UnlabelledLabel as N, type LabelVerification as O, type PostedShare as P, type ShareLabelVerifyMode as Q, type ShareLabelCheck as R, type ShareLabel as S, verifyShareLabel as T, type UnreadableShare as U, type ValidationResult as V, verifyShareLabels as W, type EIP712Type as X, type ACPPrivate as Y, type ACPType as Z, type ACPOf as _, type StoredValueLabel as a, type SharingACP as a0, type RecipientACP as a1, ACPScope as a2, type ACPScopeOptions as a3, type ACPAccessStatus as a4, type ACPHashFields as a5, type Expand as a6, type ACPPublic as b, type ACPSignaturePrimaryType as c, type EIP712Types as d, type EIP712Message as e, type SerializedACP as f, type CreateSharingACPOptions as g, type ACPMetadata as h, type SharedACP as i, type IncomingShare as j, type EIP712Domain as k, ACPUtils as l, getAclAddress as m, getAclServedAddresses as n, clearAclServedAddresses as o, type AclServedAddresses as p, type SealingKeyPair as q, type EthEncryptedData as r, seal as s, ACP_REVOKER_ABI as t, unsealWithPrivateKey as u, ACP_SHARE_REGISTRY_ABI as v, ACP_SHARE_TUPLE_ABI as w, toChainShare as x, computeShareId as y, shareIdOfChainShare as z };
|
package/dist/web.cjs
CHANGED
|
@@ -3292,23 +3292,25 @@ var getBlockRevokerData = async (publicClient) => {
|
|
|
3292
3292
|
}
|
|
3293
3293
|
return revokerData;
|
|
3294
3294
|
};
|
|
3295
|
-
var
|
|
3295
|
+
var prepareRevokeACP = (acp) => {
|
|
3296
3296
|
if (acp.revokerContract === viem.zeroAddress || acp.revokerData === 0) {
|
|
3297
3297
|
throw new Error("ACP is not revocable: it has no revoker (revokerContract/revokerData unset)");
|
|
3298
3298
|
}
|
|
3299
|
+
return {
|
|
3300
|
+
address: acp.revokerContract,
|
|
3301
|
+
abi: ACP_REVOKER_ABI,
|
|
3302
|
+
functionName: "revokeSingle",
|
|
3303
|
+
args: [BigInt(acp.revokerData)]
|
|
3304
|
+
};
|
|
3305
|
+
};
|
|
3306
|
+
var revokeACP = async (acp, walletClient) => {
|
|
3307
|
+
const write = prepareRevokeACP(acp);
|
|
3299
3308
|
if (walletClient.account == null)
|
|
3300
3309
|
throw new Error("Missing walletClient account");
|
|
3301
3310
|
if (walletClient.account.address.toLowerCase() !== acp.issuer.toLowerCase()) {
|
|
3302
3311
|
throw new Error("Only the acp issuer can revoke it");
|
|
3303
3312
|
}
|
|
3304
|
-
return walletClient.writeContract({
|
|
3305
|
-
address: acp.revokerContract,
|
|
3306
|
-
abi: ACP_REVOKER_ABI,
|
|
3307
|
-
functionName: "revokeSingle",
|
|
3308
|
-
args: [BigInt(acp.revokerData)],
|
|
3309
|
-
account: walletClient.account,
|
|
3310
|
-
chain: walletClient.chain
|
|
3311
|
-
});
|
|
3313
|
+
return walletClient.writeContract({ ...write, account: walletClient.account, chain: walletClient.chain });
|
|
3312
3314
|
};
|
|
3313
3315
|
var revokeAllACPs = async (walletClient, publicClient, revokerContract) => {
|
|
3314
3316
|
if (walletClient.account == null)
|
|
@@ -3359,28 +3361,36 @@ var metadataOf = (acp, { labels, metadata, appKey }) => {
|
|
|
3359
3361
|
}
|
|
3360
3362
|
return encodeShareMetadata(labels, { issuer: acp.issuer, appKey });
|
|
3361
3363
|
};
|
|
3362
|
-
var
|
|
3364
|
+
var prepareShareOnChain = (acp, registry, options = {}) => {
|
|
3363
3365
|
if (acp.type !== "sharing") {
|
|
3364
3366
|
throw new Error(`Cannot share a '${acp.type}' ACP on-chain \u2014 only 'sharing' ACPs are shareable.`);
|
|
3365
3367
|
}
|
|
3366
3368
|
if (acp.issuerSignature === "0x") {
|
|
3367
3369
|
throw new Error("Cannot share an unsigned sharing ACP \u2014 sign it first.");
|
|
3368
3370
|
}
|
|
3371
|
+
return {
|
|
3372
|
+
write: {
|
|
3373
|
+
address: registry,
|
|
3374
|
+
abi: ACP_SHARE_REGISTRY_ABI,
|
|
3375
|
+
functionName: "share",
|
|
3376
|
+
args: [toChainShare(acp), metadataOf(acp, options)]
|
|
3377
|
+
},
|
|
3378
|
+
shareId: computeShareId(acp)
|
|
3379
|
+
};
|
|
3380
|
+
};
|
|
3381
|
+
var shareOnChain = async (acp, walletClient, registry, options = {}) => {
|
|
3382
|
+
const { write, shareId } = prepareShareOnChain(acp, registry, options);
|
|
3369
3383
|
if (walletClient.account == null)
|
|
3370
3384
|
throw new Error("Missing walletClient account");
|
|
3371
3385
|
if (walletClient.account.address.toLowerCase() !== acp.issuer.toLowerCase()) {
|
|
3372
3386
|
throw new Error("Only the ACP issuer can share it on-chain");
|
|
3373
3387
|
}
|
|
3374
|
-
const metadata = metadataOf(acp, options);
|
|
3375
3388
|
const txHash = await walletClient.writeContract({
|
|
3376
|
-
|
|
3377
|
-
abi: ACP_SHARE_REGISTRY_ABI,
|
|
3378
|
-
functionName: "share",
|
|
3379
|
-
args: [toChainShare(acp), metadata],
|
|
3389
|
+
...write,
|
|
3380
3390
|
account: walletClient.account,
|
|
3381
3391
|
chain: walletClient.chain ?? null
|
|
3382
3392
|
});
|
|
3383
|
-
return { txHash, shareId
|
|
3393
|
+
return { txHash, shareId };
|
|
3384
3394
|
};
|
|
3385
3395
|
var toIncomingShare = ({ shareId, share: s, metadata }) => ({
|
|
3386
3396
|
shareId,
|
|
@@ -3415,14 +3425,17 @@ var importFromChain = async (share, publicClient, walletClient, importOptions =
|
|
|
3415
3425
|
const { shareId: _shareId, appKey: _appKey, ...options } = share;
|
|
3416
3426
|
return importShared({ ...options, type: "sharing" }, publicClient, walletClient, importOptions);
|
|
3417
3427
|
};
|
|
3428
|
+
var prepareRemoveShare = (shareId, registry) => ({
|
|
3429
|
+
address: registry,
|
|
3430
|
+
abi: ACP_SHARE_REGISTRY_ABI,
|
|
3431
|
+
functionName: "removeShare",
|
|
3432
|
+
args: [shareId]
|
|
3433
|
+
});
|
|
3418
3434
|
var removeShareOnChain = async (shareId, walletClient, registry) => {
|
|
3419
3435
|
if (walletClient.account == null)
|
|
3420
3436
|
throw new Error("Missing walletClient account");
|
|
3421
3437
|
return walletClient.writeContract({
|
|
3422
|
-
|
|
3423
|
-
abi: ACP_SHARE_REGISTRY_ABI,
|
|
3424
|
-
functionName: "removeShare",
|
|
3425
|
-
args: [shareId],
|
|
3438
|
+
...prepareRemoveShare(shareId, registry),
|
|
3426
3439
|
account: walletClient.account,
|
|
3427
3440
|
chain: walletClient.chain ?? null
|
|
3428
3441
|
});
|
|
@@ -3449,14 +3462,17 @@ var acps = {
|
|
|
3449
3462
|
selectActiveACP,
|
|
3450
3463
|
removeActiveACP,
|
|
3451
3464
|
revokeACP,
|
|
3465
|
+
prepareRevokeACP,
|
|
3452
3466
|
revokeAllACPs,
|
|
3453
3467
|
isACPRevoked,
|
|
3454
3468
|
checkAccess,
|
|
3455
3469
|
shareOnChain,
|
|
3470
|
+
prepareShareOnChain,
|
|
3456
3471
|
getIncomingShares,
|
|
3457
3472
|
getShareFromChain,
|
|
3458
3473
|
importFromChain,
|
|
3459
3474
|
removeShareOnChain,
|
|
3475
|
+
prepareRemoveShare,
|
|
3460
3476
|
computeShareId,
|
|
3461
3477
|
applyACPDefaultsFromChain,
|
|
3462
3478
|
getAclServedAddresses,
|
|
@@ -5232,6 +5248,12 @@ function createCofheClientBase(opts) {
|
|
|
5232
5248
|
});
|
|
5233
5249
|
}
|
|
5234
5250
|
};
|
|
5251
|
+
const _requireIssuer = (acp, what) => {
|
|
5252
|
+
const sender = connectStore.getState().walletClient?.account?.address;
|
|
5253
|
+
if (sender == null || sender.toLowerCase() !== acp.issuer.toLowerCase()) {
|
|
5254
|
+
throw new Error(`Only the acp issuer can ${what}`);
|
|
5255
|
+
}
|
|
5256
|
+
};
|
|
5235
5257
|
async function connect(publicClient, walletClient) {
|
|
5236
5258
|
const state = connectStore.getState();
|
|
5237
5259
|
if (state.connected && state.publicClient === publicClient && state.walletClient === walletClient)
|
|
@@ -5399,6 +5421,11 @@ function createCofheClientBase(opts) {
|
|
|
5399
5421
|
const { walletClient } = connectStore.getState();
|
|
5400
5422
|
return acps.revokeACP(acp, walletClient);
|
|
5401
5423
|
},
|
|
5424
|
+
prepareRevokeACP: (acp) => {
|
|
5425
|
+
_requireConnected();
|
|
5426
|
+
_requireIssuer(acp, "revoke it");
|
|
5427
|
+
return acps.prepareRevokeACP(acp);
|
|
5428
|
+
},
|
|
5402
5429
|
revokeAllACPs: async (revokerContract) => {
|
|
5403
5430
|
_requireConnected();
|
|
5404
5431
|
const { publicClient, walletClient } = connectStore.getState();
|
|
@@ -5422,6 +5449,21 @@ function createCofheClientBase(opts) {
|
|
|
5422
5449
|
const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
|
|
5423
5450
|
return acps.shareOnChain(acp, walletClient, sharingRegistry, { ...withAppKey(), ...options });
|
|
5424
5451
|
},
|
|
5452
|
+
prepareShareOnChain: async (acp, options) => {
|
|
5453
|
+
_requireConnected();
|
|
5454
|
+
_requireIssuer(acp, "share it on-chain");
|
|
5455
|
+
const { publicClient } = connectStore.getState();
|
|
5456
|
+
const chainId = await publicClient.getChainId();
|
|
5457
|
+
const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
|
|
5458
|
+
return acps.prepareShareOnChain(acp, sharingRegistry, { ...withAppKey(), ...options });
|
|
5459
|
+
},
|
|
5460
|
+
prepareRemoveShare: async (shareId) => {
|
|
5461
|
+
_requireConnected();
|
|
5462
|
+
const { publicClient } = connectStore.getState();
|
|
5463
|
+
const chainId = await publicClient.getChainId();
|
|
5464
|
+
const sharingRegistry = await _resolveSharingRegistry(publicClient, chainId);
|
|
5465
|
+
return acps.prepareRemoveShare(shareId, sharingRegistry);
|
|
5466
|
+
},
|
|
5425
5467
|
getIncomingShares: async () => {
|
|
5426
5468
|
_requireConnected();
|
|
5427
5469
|
const { publicClient, walletClient } = connectStore.getState();
|
package/dist/web.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-
|
|
1
|
+
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-RXwLVWou.cjs';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './types-C07FK-cL.cjs';
|
|
4
4
|
import 'zod';
|
|
5
|
-
import './onchain-utils-
|
|
5
|
+
import './onchain-utils-Ns56cBm0.cjs';
|
|
6
6
|
import 'zustand/vanilla';
|
|
7
7
|
|
|
8
8
|
declare function createSsrStorage(): IStorage;
|
package/dist/web.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-
|
|
1
|
+
import { I as IStorage, C as CofheInputConfig, a as CofheConfig, b as CofheClient, E as EncryptableItem } from './clientTypes-CnslFzxB.js';
|
|
2
2
|
import 'viem';
|
|
3
3
|
import './types-C07FK-cL.js';
|
|
4
4
|
import 'zod';
|
|
5
|
-
import './onchain-utils-
|
|
5
|
+
import './onchain-utils-Ns56cBm0.js';
|
|
6
6
|
import 'zustand/vanilla';
|
|
7
7
|
|
|
8
8
|
declare function createSsrStorage(): IStorage;
|
package/dist/web.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createCofheConfigBase, createCofheClientBase } from './chunk-
|
|
1
|
+
import { createCofheConfigBase, createCofheClientBase } from './chunk-2EO4JSR7.js';
|
|
2
2
|
import './chunk-UKQAJK4N.js';
|
|
3
3
|
import './chunk-3L2IVPMI.js';
|
|
4
4
|
import { initTfheThreadPool } from './chunk-KSOV5B4B.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cofhe/sdk",
|
|
3
|
-
"version": "1.0.0",
|
|
3
|
+
"version": "1.1.0-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SDK for Fhenix COFHE coprocessor interaction",
|
|
6
6
|
"main": "./dist/core.cjs",
|
|
@@ -102,8 +102,8 @@
|
|
|
102
102
|
"typescript": "5.5.4",
|
|
103
103
|
"vitest": "3.2.4",
|
|
104
104
|
"@cofhe/eslint-config": "0.2.1",
|
|
105
|
-
"@cofhe/
|
|
106
|
-
"@cofhe/
|
|
105
|
+
"@cofhe/test-setup": "0.0.0",
|
|
106
|
+
"@cofhe/tsconfig": "0.1.2"
|
|
107
107
|
},
|
|
108
108
|
"publishConfig": {
|
|
109
109
|
"access": "public",
|