@partylayer/core 0.2.3 → 0.2.4

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 CantonConnect
3
+ Copyright (c) 2024 PartyLayer
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -244,9 +244,9 @@ try {
244
244
 
245
245
  ## Links
246
246
 
247
- - [GitHub Repository](https://github.com/cayvox/PartyLayer)
248
- - [Wallet Provider Guide](https://github.com/cayvox/PartyLayer/blob/main/docs/wallet-provider-guide.md)
249
- - [Report Issues](https://github.com/cayvox/PartyLayer/issues)
247
+ - [GitHub Repository](https://github.com/PartyLayer/PartyLayer)
248
+ - [Wallet Provider Guide](https://github.com/PartyLayer/PartyLayer/blob/main/docs/wallet-provider-guide.md)
249
+ - [Report Issues](https://github.com/PartyLayer/PartyLayer/issues)
250
250
 
251
251
  ---
252
252
 
package/dist/index.d.mts CHANGED
@@ -34,7 +34,7 @@ type NetworkId = 'devnet' | 'testnet' | 'mainnet' | (string & Record<never, neve
34
34
  * Capability keys that wallets can support
35
35
  * Based on OpenRPC dApp API capabilities
36
36
  */
37
- type CapabilityKey = 'connect' | 'disconnect' | 'restore' | 'signMessage' | 'signTransaction' | 'submitTransaction' | 'events' | 'deeplink' | 'popup' | 'injected' | 'remoteSigner';
37
+ type CapabilityKey = 'connect' | 'disconnect' | 'restore' | 'signMessage' | 'signTransaction' | 'submitTransaction' | 'ledgerApi' | 'events' | 'deeplink' | 'popup' | 'injected' | 'remoteSigner';
38
38
  /**
39
39
  * Wallet installation hints for detection
40
40
  */
@@ -222,7 +222,7 @@ interface ErrorMappingContext {
222
222
  /** Wallet ID (if applicable) */
223
223
  walletId?: string;
224
224
  /** Operation phase */
225
- phase: 'connect' | 'restore' | 'signMessage' | 'signTransaction' | 'submitTransaction';
225
+ phase: 'connect' | 'restore' | 'signMessage' | 'signTransaction' | 'submitTransaction' | 'ledgerApi';
226
226
  /** Transport type */
227
227
  transport?: 'injected' | 'popup' | 'deeplink' | 'remote';
228
228
  /** Timeout in milliseconds (for timeout errors) */
@@ -389,6 +389,24 @@ interface SubmitTransactionParams {
389
389
  /** Signed transaction */
390
390
  signedTx: unknown;
391
391
  }
392
+ /**
393
+ * Ledger API proxy parameters (CIP-0103 ledgerApi method)
394
+ */
395
+ interface LedgerApiParams {
396
+ /** HTTP method for the JSON Ledger API */
397
+ requestMethod: 'GET' | 'POST' | 'PUT' | 'DELETE';
398
+ /** Resource path (e.g., "/v1/state/acs") */
399
+ resource: string;
400
+ /** Optional JSON body */
401
+ body?: string;
402
+ }
403
+ /**
404
+ * Ledger API proxy result
405
+ */
406
+ interface LedgerApiResult {
407
+ /** JSON response from the Ledger API */
408
+ response: string;
409
+ }
392
410
  /**
393
411
  * Logger interface
394
412
  */
@@ -400,10 +418,40 @@ interface LoggerAdapter {
400
418
  }
401
419
  /**
402
420
  * Telemetry interface
421
+ *
422
+ * Extended in 0.3.0 with optional metrics methods.
423
+ * All new methods are optional to maintain backward compatibility.
403
424
  */
404
425
  interface TelemetryAdapter {
426
+ /** Track a named event with optional properties */
405
427
  track(event: string, properties?: Record<string, unknown>): void;
428
+ /** Track an error occurrence */
406
429
  error(error: Error, properties?: Record<string, unknown>): void;
430
+ /**
431
+ * Increment a metric counter
432
+ * @param metric - Metric name (e.g., 'wallet_connect_attempts')
433
+ * @param value - Value to increment by (default: 1)
434
+ * @since 0.3.0
435
+ */
436
+ increment?(metric: string, value?: number): void;
437
+ /**
438
+ * Set a gauge metric value
439
+ * @param metric - Metric name
440
+ * @param value - Current value
441
+ * @since 0.3.0
442
+ */
443
+ gauge?(metric: string, value: number): void;
444
+ /**
445
+ * Flush buffered metrics to backend
446
+ * @since 0.3.0
447
+ */
448
+ flush?(): Promise<void>;
449
+ /**
450
+ * Check if telemetry is enabled
451
+ * @returns true if telemetry should be collected
452
+ * @since 0.3.0
453
+ */
454
+ isEnabled?(): boolean;
407
455
  }
408
456
  /**
409
457
  * Crypto interface
@@ -519,6 +567,13 @@ interface WalletAdapter {
519
567
  * @param params Submit transaction parameters
520
568
  */
521
569
  submitTransaction?(ctx: AdapterContext, session: Session, params: SubmitTransactionParams): Promise<TxReceipt>;
570
+ /**
571
+ * Proxy a JSON Ledger API request (optional - only if wallet supports it)
572
+ * @param ctx Adapter context
573
+ * @param session Active session
574
+ * @param params Ledger API request parameters
575
+ */
576
+ ledgerApi?(ctx: AdapterContext, session: Session, params: LedgerApiParams): Promise<LedgerApiResult>;
522
577
  /**
523
578
  * Subscribe to adapter events (optional)
524
579
  * @param event Event name
@@ -660,6 +715,287 @@ interface Transport$1 {
660
715
  pollJobStatus?(jobId: string, statusUrl: string, options: TransportOptions): Promise<JobStatus>;
661
716
  }
662
717
 
718
+ /**
719
+ * Canonical Metrics Constants
720
+ *
721
+ * These metric names are the official set for PartyLayer telemetry.
722
+ * Changing these names would break metrics aggregation and downstream reporting.
723
+ *
724
+ * @since 0.3.0
725
+ */
726
+ /**
727
+ * Enablement Metrics
728
+ *
729
+ * These metrics measure how PartyLayer enables wallet interactions.
730
+ */
731
+ declare const ENABLEMENT_METRICS: {
732
+ /** Total wallet connect() calls made */
733
+ readonly WALLET_CONNECT_ATTEMPTS: "wallet_connect_attempts";
734
+ /** Successful wallet connections (session:connected events) */
735
+ readonly WALLET_CONNECT_SUCCESS: "wallet_connect_success";
736
+ /** New sessions created (not restored) */
737
+ readonly SESSIONS_CREATED: "sessions_created";
738
+ /** Sessions successfully restored from storage */
739
+ readonly SESSIONS_RESTORED: "sessions_restored";
740
+ /** Total session restore attempts */
741
+ readonly RESTORE_ATTEMPTS: "restore_attempts";
742
+ };
743
+ /**
744
+ * Error Metrics
745
+ *
746
+ * These metrics track error occurrences by code.
747
+ */
748
+ declare const ERROR_METRICS: {
749
+ /** Prefix for error metrics (e.g., error_USER_REJECTED) */
750
+ readonly ERROR_PREFIX: "error_";
751
+ };
752
+ /**
753
+ * Registry Metrics
754
+ *
755
+ * These metrics track registry client behavior.
756
+ */
757
+ declare const REGISTRY_METRICS: {
758
+ /** Registry fetched from network */
759
+ readonly REGISTRY_FETCH: "registry_fetch";
760
+ /** Registry served from cache */
761
+ readonly REGISTRY_CACHE_HIT: "registry_cache_hit";
762
+ /** Stale registry was used */
763
+ readonly REGISTRY_STALE: "registry_stale";
764
+ };
765
+ /**
766
+ * All metrics combined
767
+ */
768
+ declare const METRICS: {
769
+ /** Registry fetched from network */
770
+ readonly REGISTRY_FETCH: "registry_fetch";
771
+ /** Registry served from cache */
772
+ readonly REGISTRY_CACHE_HIT: "registry_cache_hit";
773
+ /** Stale registry was used */
774
+ readonly REGISTRY_STALE: "registry_stale";
775
+ /** Prefix for error metrics (e.g., error_USER_REJECTED) */
776
+ readonly ERROR_PREFIX: "error_";
777
+ /** Total wallet connect() calls made */
778
+ readonly WALLET_CONNECT_ATTEMPTS: "wallet_connect_attempts";
779
+ /** Successful wallet connections (session:connected events) */
780
+ readonly WALLET_CONNECT_SUCCESS: "wallet_connect_success";
781
+ /** New sessions created (not restored) */
782
+ readonly SESSIONS_CREATED: "sessions_created";
783
+ /** Sessions successfully restored from storage */
784
+ readonly SESSIONS_RESTORED: "sessions_restored";
785
+ /** Total session restore attempts */
786
+ readonly RESTORE_ATTEMPTS: "restore_attempts";
787
+ };
788
+ /**
789
+ * Type for all metric names
790
+ */
791
+ type MetricName = typeof METRICS[keyof typeof METRICS];
792
+ /**
793
+ * Build an error metric name from an error code
794
+ *
795
+ * @param errorCode - The error code (e.g., 'USER_REJECTED')
796
+ * @returns The metric name (e.g., 'error_USER_REJECTED')
797
+ */
798
+ declare function errorMetricName(errorCode: string): string;
799
+
800
+ /**
801
+ * Metrics Payload Types and Privacy Validation
802
+ *
803
+ * This module defines the privacy-safe payload format for metrics collection.
804
+ *
805
+ * Privacy Guarantees:
806
+ * - NO wallet addresses
807
+ * - NO raw party IDs
808
+ * - NO transaction payloads
809
+ * - NO signed message content
810
+ * - NO user identifiers
811
+ *
812
+ * @since 0.3.0
813
+ */
814
+ /**
815
+ * Privacy-safe metrics payload
816
+ *
817
+ * This is the only payload format accepted by the metrics backend.
818
+ */
819
+ interface MetricsPayload {
820
+ /** SDK version (e.g., '0.3.0') */
821
+ sdkVersion: string;
822
+ /** Network identifier (e.g., 'devnet', 'mainnet') */
823
+ network: string;
824
+ /** Unix timestamp in milliseconds */
825
+ timestamp: number;
826
+ /** Metric name → value map */
827
+ metrics: Record<string, number>;
828
+ /** Hashed app identifier (opt-in, SHA-256) */
829
+ appIdHash?: string;
830
+ /** Hashed origin (opt-in, SHA-256) */
831
+ originHash?: string;
832
+ }
833
+ /**
834
+ * Validate that a payload is privacy-safe
835
+ *
836
+ * @param payload - Unknown payload to validate
837
+ * @returns true if payload is valid MetricsPayload with no PII
838
+ * @throws Error if forbidden fields are detected
839
+ */
840
+ declare function validatePayload(payload: unknown): payload is MetricsPayload;
841
+ /**
842
+ * Hash a string using SHA-256 (browser-compatible)
843
+ *
844
+ * @param value - String to hash
845
+ * @returns Hex-encoded SHA-256 hash
846
+ */
847
+ declare function hashForPrivacy(value: string): Promise<string>;
848
+ /**
849
+ * Create a sanitized metrics payload
850
+ *
851
+ * This function ensures the payload is privacy-safe before sending.
852
+ *
853
+ * @param data - Raw metrics data
854
+ * @returns Sanitized MetricsPayload
855
+ */
856
+ declare function createMetricsPayload(data: {
857
+ sdkVersion: string;
858
+ network: string;
859
+ metrics: Record<string, number>;
860
+ appIdHash?: string;
861
+ originHash?: string;
862
+ }): MetricsPayload;
863
+
864
+ /**
865
+ * CIP-0103 dApp Standard — Canonical Type Definitions
866
+ *
867
+ * These types are the verbatim representation of the CIP-0103 specification.
868
+ * They live in @partylayer/core so both @partylayer/provider and @partylayer/sdk
869
+ * can reference them without circular dependencies.
870
+ *
871
+ * Reference: https://github.com/canton-foundation/cips/blob/main/cip-0103/cip-0103.md
872
+ *
873
+ * IMPORTANT: Do not add PartyLayer-specific fields or aliases.
874
+ * These types represent the standard exactly.
875
+ */
876
+ type CIP0103EventListener<T = unknown> = (...args: T[]) => void;
877
+ type CIP0103RequestParams = unknown[] | Record<string, unknown>;
878
+ interface CIP0103RequestPayload {
879
+ method: string;
880
+ params?: CIP0103RequestParams;
881
+ }
882
+ interface CIP0103Provider {
883
+ request<T = unknown>(args: CIP0103RequestPayload): Promise<T>;
884
+ on<T = unknown>(event: string, listener: CIP0103EventListener<T>): CIP0103Provider;
885
+ emit<T = unknown>(event: string, ...args: T[]): boolean;
886
+ removeListener<T = unknown>(event: string, listenerToRemove: CIP0103EventListener<T>): CIP0103Provider;
887
+ }
888
+ interface CIP0103ConnectResult {
889
+ isConnected: boolean;
890
+ reason?: string;
891
+ isNetworkConnected?: boolean;
892
+ networkReason?: string;
893
+ /** Async wallet extension: URL for user to complete connection */
894
+ userUrl?: string;
895
+ }
896
+ interface CIP0103Network {
897
+ /** CAIP-2 network identifier, e.g. "canton:da-mainnet" */
898
+ networkId: string;
899
+ /** JSON Ledger API endpoint (if available) */
900
+ ledgerApi?: string;
901
+ /** Access token for Ledger API (if available) */
902
+ accessToken?: string;
903
+ }
904
+ type CIP0103AccountStatus = 'initializing' | 'allocated';
905
+ interface CIP0103Account {
906
+ primary: boolean;
907
+ partyId: string;
908
+ status: CIP0103AccountStatus;
909
+ hint: string;
910
+ publicKey: string;
911
+ namespace: string;
912
+ /** CAIP-2 network identifier */
913
+ networkId: string;
914
+ signingProviderId: string;
915
+ }
916
+ type CIP0103ProviderType = 'browser' | 'desktop' | 'mobile' | 'remote';
917
+ interface CIP0103ProviderInfo {
918
+ id: string;
919
+ /** dApp API version */
920
+ version: string;
921
+ providerType: CIP0103ProviderType;
922
+ }
923
+ interface CIP0103StatusEvent {
924
+ connection: CIP0103ConnectResult;
925
+ provider: CIP0103ProviderInfo;
926
+ network?: CIP0103Network;
927
+ session?: {
928
+ accessToken: string;
929
+ userId: string;
930
+ };
931
+ }
932
+ type CIP0103TxStatus = 'pending' | 'signed' | 'executed' | 'failed';
933
+ interface CIP0103TxPendingPayload {
934
+ status: 'pending';
935
+ commandId: string;
936
+ }
937
+ interface CIP0103TxSignedPayload {
938
+ status: 'signed';
939
+ commandId: string;
940
+ payload: {
941
+ signature: string;
942
+ signedBy: string;
943
+ party: string;
944
+ };
945
+ }
946
+ interface CIP0103TxExecutedPayload {
947
+ status: 'executed';
948
+ commandId: string;
949
+ payload: {
950
+ updateId: string;
951
+ completionOffset: number;
952
+ };
953
+ }
954
+ interface CIP0103TxFailedPayload {
955
+ status: 'failed';
956
+ commandId: string;
957
+ }
958
+ type CIP0103TxChangedEvent = CIP0103TxPendingPayload | CIP0103TxSignedPayload | CIP0103TxExecutedPayload | CIP0103TxFailedPayload;
959
+ interface CIP0103LedgerApiRequest {
960
+ requestMethod: 'GET' | 'POST' | 'PUT' | 'DELETE';
961
+ resource: string;
962
+ body?: string;
963
+ }
964
+ interface CIP0103LedgerApiResponse {
965
+ response: string;
966
+ }
967
+ interface CIP0103SignMessageRequest {
968
+ message: string;
969
+ }
970
+ interface CIP0103ProviderRpcError {
971
+ code: number;
972
+ message: string;
973
+ data?: unknown;
974
+ }
975
+ declare const CIP0103_METHODS: {
976
+ readonly CONNECT: "connect";
977
+ readonly DISCONNECT: "disconnect";
978
+ readonly IS_CONNECTED: "isConnected";
979
+ readonly STATUS: "status";
980
+ readonly GET_ACTIVE_NETWORK: "getActiveNetwork";
981
+ readonly LIST_ACCOUNTS: "listAccounts";
982
+ readonly GET_PRIMARY_ACCOUNT: "getPrimaryAccount";
983
+ readonly SIGN_MESSAGE: "signMessage";
984
+ readonly PREPARE_EXECUTE: "prepareExecute";
985
+ readonly LEDGER_API: "ledgerApi";
986
+ };
987
+ type CIP0103Method = (typeof CIP0103_METHODS)[keyof typeof CIP0103_METHODS];
988
+ /** All mandatory method names as an array (useful for conformance testing) */
989
+ declare const CIP0103_MANDATORY_METHODS: readonly CIP0103Method[];
990
+ declare const CIP0103_EVENTS: {
991
+ readonly STATUS_CHANGED: "statusChanged";
992
+ readonly ACCOUNTS_CHANGED: "accountsChanged";
993
+ readonly TX_CHANGED: "txChanged";
994
+ /** Emitted when async connect completes */
995
+ readonly CONNECTED: "connected";
996
+ };
997
+ type CIP0103Event = (typeof CIP0103_EVENTS)[keyof typeof CIP0103_EVENTS];
998
+
663
999
  /**
664
1000
  * Deep Link Transport
665
1001
  *
@@ -882,4 +1218,4 @@ interface Transport {
882
1218
  disconnect(): Promise<void>;
883
1219
  }
884
1220
 
885
- export { type AdapterConnectResult, type AdapterContext, type AdapterDetectResult, type AdapterEventName, type AdapterMetadata, type CapabilityKey, CapabilityNotSupportedError, type ConnectRequest, type ConnectResponse, type CryptoAdapter, DeepLinkTransport, type ErrorCode, type ErrorMappingContext, type InstallHints, InternalError, type JobStatus, type LoggerAdapter, MockTransport, type NetworkId, OriginNotAllowedError, type PartyId, PartyLayerError, type PersistedSession, PopupTransport, PostMessageTransport, type RegistryClientAdapter, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, type Session, SessionExpiredError, type SessionId, type SignMessageParams, type SignRequest, type SignResponse, type SignTransactionParams, type Signature, type SignedMessage, type SignedTransaction, type StorageAdapter, type SubmitTransactionParams, type TelemetryAdapter, TimeoutError, type TransactionHash, type TransactionStatus, type Transport, TransportError, type TransportOptions, type TransportType, type TxReceipt, type TxStatusUpdate, UserRejectedError, type WalletAdapter, type WalletId, type WalletInfo, WalletNotFoundError, WalletNotInstalledError, capabilityGuard, createSession, generateSessionId, installGuard, isSessionExpired, mapUnknownErrorToPartyLayerError, toPartyId, toSessionId, toSignature, toTransactionHash, toWalletId, validateSession };
1221
+ export { type AdapterConnectResult, type AdapterContext, type AdapterDetectResult, type AdapterEventName, type AdapterMetadata, type CIP0103Account, type CIP0103AccountStatus, type CIP0103ConnectResult, type CIP0103Event, type CIP0103EventListener, type CIP0103LedgerApiRequest, type CIP0103LedgerApiResponse, type CIP0103Method, type CIP0103Network, type CIP0103Provider, type CIP0103ProviderInfo, type CIP0103ProviderRpcError, type CIP0103ProviderType, type CIP0103RequestParams, type CIP0103RequestPayload, type CIP0103SignMessageRequest, type CIP0103StatusEvent, type CIP0103TxChangedEvent, type CIP0103TxExecutedPayload, type CIP0103TxFailedPayload, type CIP0103TxPendingPayload, type CIP0103TxSignedPayload, type CIP0103TxStatus, CIP0103_EVENTS, CIP0103_MANDATORY_METHODS, CIP0103_METHODS, type CapabilityKey, CapabilityNotSupportedError, type ConnectRequest, type ConnectResponse, type CryptoAdapter, DeepLinkTransport, ENABLEMENT_METRICS, ERROR_METRICS, type ErrorCode, type ErrorMappingContext, type InstallHints, InternalError, type JobStatus, type LedgerApiParams, type LedgerApiResult, type LoggerAdapter, METRICS, type MetricName, type MetricsPayload, MockTransport, type NetworkId, OriginNotAllowedError, type PartyId, PartyLayerError, type PersistedSession, PopupTransport, PostMessageTransport, REGISTRY_METRICS, type RegistryClientAdapter, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, type Session, SessionExpiredError, type SessionId, type SignMessageParams, type SignRequest, type SignResponse, type SignTransactionParams, type Signature, type SignedMessage, type SignedTransaction, type StorageAdapter, type SubmitTransactionParams, type TelemetryAdapter, TimeoutError, type TransactionHash, type TransactionStatus, type Transport, TransportError, type TransportOptions, type TransportType, type TxReceipt, type TxStatusUpdate, UserRejectedError, type WalletAdapter, type WalletId, type WalletInfo, WalletNotFoundError, WalletNotInstalledError, capabilityGuard, createMetricsPayload, createSession, errorMetricName, generateSessionId, hashForPrivacy, installGuard, isSessionExpired, mapUnknownErrorToPartyLayerError, toPartyId, toSessionId, toSignature, toTransactionHash, toWalletId, validatePayload, validateSession };