@partylayer/core 0.2.2 → 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 +1 -1
- package/README.md +3 -3
- package/dist/index.d.mts +340 -4
- package/dist/index.d.ts +340 -4
- package/dist/index.js +159 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Core types for
|
|
2
|
+
* Core types for PartyLayer SDK
|
|
3
3
|
*
|
|
4
4
|
* References:
|
|
5
5
|
* - Wallet Integration Guide: https://docs.digitalasset.com/integrate/devnet/index.html
|
|
@@ -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 };
|
package/dist/index.js
CHANGED
|
@@ -275,6 +275,153 @@ function createSession(walletId, partyId, network, origin, capabilities = [], ex
|
|
|
275
275
|
};
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
+
// src/metrics.ts
|
|
279
|
+
var ENABLEMENT_METRICS = {
|
|
280
|
+
/** Total wallet connect() calls made */
|
|
281
|
+
WALLET_CONNECT_ATTEMPTS: "wallet_connect_attempts",
|
|
282
|
+
/** Successful wallet connections (session:connected events) */
|
|
283
|
+
WALLET_CONNECT_SUCCESS: "wallet_connect_success",
|
|
284
|
+
/** New sessions created (not restored) */
|
|
285
|
+
SESSIONS_CREATED: "sessions_created",
|
|
286
|
+
/** Sessions successfully restored from storage */
|
|
287
|
+
SESSIONS_RESTORED: "sessions_restored",
|
|
288
|
+
/** Total session restore attempts */
|
|
289
|
+
RESTORE_ATTEMPTS: "restore_attempts"
|
|
290
|
+
};
|
|
291
|
+
var ERROR_METRICS = {
|
|
292
|
+
/** Prefix for error metrics (e.g., error_USER_REJECTED) */
|
|
293
|
+
ERROR_PREFIX: "error_"
|
|
294
|
+
};
|
|
295
|
+
var REGISTRY_METRICS = {
|
|
296
|
+
/** Registry fetched from network */
|
|
297
|
+
REGISTRY_FETCH: "registry_fetch",
|
|
298
|
+
/** Registry served from cache */
|
|
299
|
+
REGISTRY_CACHE_HIT: "registry_cache_hit",
|
|
300
|
+
/** Stale registry was used */
|
|
301
|
+
REGISTRY_STALE: "registry_stale"
|
|
302
|
+
};
|
|
303
|
+
var METRICS = {
|
|
304
|
+
...ENABLEMENT_METRICS,
|
|
305
|
+
...ERROR_METRICS,
|
|
306
|
+
...REGISTRY_METRICS
|
|
307
|
+
};
|
|
308
|
+
function errorMetricName(errorCode) {
|
|
309
|
+
return `${METRICS.ERROR_PREFIX}${errorCode}`;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// src/metrics-payload.ts
|
|
313
|
+
var FORBIDDEN_FIELDS = [
|
|
314
|
+
"walletAddress",
|
|
315
|
+
"address",
|
|
316
|
+
"partyId",
|
|
317
|
+
"rawPartyId",
|
|
318
|
+
"publicKey",
|
|
319
|
+
"privateKey",
|
|
320
|
+
"seed",
|
|
321
|
+
"mnemonic",
|
|
322
|
+
"txPayload",
|
|
323
|
+
"transaction",
|
|
324
|
+
"signedMessage",
|
|
325
|
+
"message",
|
|
326
|
+
"signature",
|
|
327
|
+
"userId",
|
|
328
|
+
"email",
|
|
329
|
+
"name",
|
|
330
|
+
"ip",
|
|
331
|
+
"userAgent"
|
|
332
|
+
];
|
|
333
|
+
function validatePayload(payload) {
|
|
334
|
+
if (!payload || typeof payload !== "object") {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
const obj = payload;
|
|
338
|
+
for (const field of FORBIDDEN_FIELDS) {
|
|
339
|
+
if (field in obj) {
|
|
340
|
+
throw new Error(`Forbidden field detected in metrics payload: ${field}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (typeof obj.sdkVersion !== "string") {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
if (typeof obj.network !== "string") {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
if (typeof obj.timestamp !== "number" || obj.timestamp <= 0) {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
if (!obj.metrics || typeof obj.metrics !== "object") {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
for (const [key, value] of Object.entries(obj.metrics)) {
|
|
356
|
+
if (typeof key !== "string" || typeof value !== "number") {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (obj.appIdHash !== void 0 && typeof obj.appIdHash !== "string") {
|
|
361
|
+
return false;
|
|
362
|
+
}
|
|
363
|
+
if (obj.originHash !== void 0 && typeof obj.originHash !== "string") {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
async function hashForPrivacy(value) {
|
|
369
|
+
if (typeof crypto === "undefined" || !crypto.subtle) {
|
|
370
|
+
let hash = 0;
|
|
371
|
+
for (let i = 0; i < value.length; i++) {
|
|
372
|
+
const char = value.charCodeAt(i);
|
|
373
|
+
hash = (hash << 5) - hash + char;
|
|
374
|
+
hash = hash & hash;
|
|
375
|
+
}
|
|
376
|
+
return Math.abs(hash).toString(16).padStart(8, "0");
|
|
377
|
+
}
|
|
378
|
+
const encoder = new TextEncoder();
|
|
379
|
+
const data = encoder.encode(value);
|
|
380
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
381
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
382
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
383
|
+
}
|
|
384
|
+
function createMetricsPayload(data) {
|
|
385
|
+
const payload = {
|
|
386
|
+
sdkVersion: data.sdkVersion,
|
|
387
|
+
network: data.network,
|
|
388
|
+
timestamp: Date.now(),
|
|
389
|
+
metrics: { ...data.metrics }
|
|
390
|
+
};
|
|
391
|
+
if (data.appIdHash) {
|
|
392
|
+
payload.appIdHash = data.appIdHash;
|
|
393
|
+
}
|
|
394
|
+
if (data.originHash) {
|
|
395
|
+
payload.originHash = data.originHash;
|
|
396
|
+
}
|
|
397
|
+
if (!validatePayload(payload)) {
|
|
398
|
+
throw new Error("Failed to create valid metrics payload");
|
|
399
|
+
}
|
|
400
|
+
return payload;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// src/cip0103-types.ts
|
|
404
|
+
var CIP0103_METHODS = {
|
|
405
|
+
CONNECT: "connect",
|
|
406
|
+
DISCONNECT: "disconnect",
|
|
407
|
+
IS_CONNECTED: "isConnected",
|
|
408
|
+
STATUS: "status",
|
|
409
|
+
GET_ACTIVE_NETWORK: "getActiveNetwork",
|
|
410
|
+
LIST_ACCOUNTS: "listAccounts",
|
|
411
|
+
GET_PRIMARY_ACCOUNT: "getPrimaryAccount",
|
|
412
|
+
SIGN_MESSAGE: "signMessage",
|
|
413
|
+
PREPARE_EXECUTE: "prepareExecute",
|
|
414
|
+
LEDGER_API: "ledgerApi"
|
|
415
|
+
};
|
|
416
|
+
var CIP0103_MANDATORY_METHODS = Object.values(CIP0103_METHODS);
|
|
417
|
+
var CIP0103_EVENTS = {
|
|
418
|
+
STATUS_CHANGED: "statusChanged",
|
|
419
|
+
ACCOUNTS_CHANGED: "accountsChanged",
|
|
420
|
+
TX_CHANGED: "txChanged",
|
|
421
|
+
/** Emitted when async connect completes */
|
|
422
|
+
CONNECTED: "connected"
|
|
423
|
+
};
|
|
424
|
+
|
|
278
425
|
// src/transport/deeplink.ts
|
|
279
426
|
var DeepLinkTransport = class {
|
|
280
427
|
/**
|
|
@@ -464,7 +611,7 @@ var PopupTransport = class {
|
|
|
464
611
|
const top = window.screenY + (window.outerHeight - height) / 2;
|
|
465
612
|
return window.open(
|
|
466
613
|
url,
|
|
467
|
-
"
|
|
614
|
+
"PartyLayer",
|
|
468
615
|
`width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`
|
|
469
616
|
);
|
|
470
617
|
}
|
|
@@ -753,14 +900,21 @@ var MockTransport = class {
|
|
|
753
900
|
}
|
|
754
901
|
};
|
|
755
902
|
|
|
903
|
+
exports.CIP0103_EVENTS = CIP0103_EVENTS;
|
|
904
|
+
exports.CIP0103_MANDATORY_METHODS = CIP0103_MANDATORY_METHODS;
|
|
905
|
+
exports.CIP0103_METHODS = CIP0103_METHODS;
|
|
756
906
|
exports.CapabilityNotSupportedError = CapabilityNotSupportedError;
|
|
757
907
|
exports.DeepLinkTransport = DeepLinkTransport;
|
|
908
|
+
exports.ENABLEMENT_METRICS = ENABLEMENT_METRICS;
|
|
909
|
+
exports.ERROR_METRICS = ERROR_METRICS;
|
|
758
910
|
exports.InternalError = InternalError;
|
|
911
|
+
exports.METRICS = METRICS;
|
|
759
912
|
exports.MockTransport = MockTransport;
|
|
760
913
|
exports.OriginNotAllowedError = OriginNotAllowedError;
|
|
761
914
|
exports.PartyLayerError = PartyLayerError;
|
|
762
915
|
exports.PopupTransport = PopupTransport;
|
|
763
916
|
exports.PostMessageTransport = PostMessageTransport;
|
|
917
|
+
exports.REGISTRY_METRICS = REGISTRY_METRICS;
|
|
764
918
|
exports.RegistryFetchFailedError = RegistryFetchFailedError;
|
|
765
919
|
exports.RegistrySchemaInvalidError = RegistrySchemaInvalidError;
|
|
766
920
|
exports.RegistryVerificationFailedError = RegistryVerificationFailedError;
|
|
@@ -771,8 +925,11 @@ exports.UserRejectedError = UserRejectedError;
|
|
|
771
925
|
exports.WalletNotFoundError = WalletNotFoundError;
|
|
772
926
|
exports.WalletNotInstalledError = WalletNotInstalledError;
|
|
773
927
|
exports.capabilityGuard = capabilityGuard;
|
|
928
|
+
exports.createMetricsPayload = createMetricsPayload;
|
|
774
929
|
exports.createSession = createSession;
|
|
930
|
+
exports.errorMetricName = errorMetricName;
|
|
775
931
|
exports.generateSessionId = generateSessionId;
|
|
932
|
+
exports.hashForPrivacy = hashForPrivacy;
|
|
776
933
|
exports.installGuard = installGuard;
|
|
777
934
|
exports.isSessionExpired = isSessionExpired;
|
|
778
935
|
exports.mapUnknownErrorToPartyLayerError = mapUnknownErrorToPartyLayerError;
|
|
@@ -781,6 +938,7 @@ exports.toSessionId = toSessionId;
|
|
|
781
938
|
exports.toSignature = toSignature;
|
|
782
939
|
exports.toTransactionHash = toTransactionHash;
|
|
783
940
|
exports.toWalletId = toWalletId;
|
|
941
|
+
exports.validatePayload = validatePayload;
|
|
784
942
|
exports.validateSession = validateSession;
|
|
785
943
|
//# sourceMappingURL=index.js.map
|
|
786
944
|
//# sourceMappingURL=index.js.map
|