@railgun-community/shared-models 7.5.0 → 7.5.2
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.
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
import { TXIDVersion } from './engine';
|
|
3
3
|
import { NetworkName } from './network-config';
|
|
4
4
|
import { PreTransactionPOIsPerTxidLeafPerList } from './response-types';
|
|
5
|
+
export type ChainParams = {
|
|
6
|
+
chainType: string;
|
|
7
|
+
chainID: string;
|
|
8
|
+
txidVersion: TXIDVersion;
|
|
9
|
+
};
|
|
5
10
|
export type TransactProofData = {
|
|
6
11
|
snarkProof: SnarkProof;
|
|
7
12
|
poiMerkleroots: string[];
|
|
@@ -44,14 +49,10 @@ export type POIListStatus = {
|
|
|
44
49
|
historicalMerklerootsLength: number;
|
|
45
50
|
latestHistoricalMerkleroot: string;
|
|
46
51
|
};
|
|
47
|
-
export type GetTransactProofsParams = {
|
|
48
|
-
txidVersion: TXIDVersion;
|
|
49
|
-
bloomFilterSerialized: string;
|
|
52
|
+
export type GetTransactProofsParams = ChainParams & {
|
|
50
53
|
listKey: string;
|
|
51
54
|
};
|
|
52
|
-
export type GetBlockedShieldsParams = {
|
|
53
|
-
txidVersion: TXIDVersion;
|
|
54
|
-
bloomFilterSerialized: string;
|
|
55
|
+
export type GetBlockedShieldsParams = ChainParams & {
|
|
55
56
|
listKey: string;
|
|
56
57
|
};
|
|
57
58
|
export type LegacyTransactProofData = {
|
|
@@ -70,24 +71,15 @@ export type SingleCommitmentProofsData = {
|
|
|
70
71
|
railgunTxid: string;
|
|
71
72
|
pois: PreTransactionPOIsPerTxidLeafPerList;
|
|
72
73
|
};
|
|
73
|
-
export type SubmitTransactProofParams = {
|
|
74
|
-
chainType: string;
|
|
75
|
-
chainID: string;
|
|
76
|
-
txidVersion: TXIDVersion;
|
|
74
|
+
export type SubmitTransactProofParams = ChainParams & {
|
|
77
75
|
listKey: string;
|
|
78
76
|
transactProofData: TransactProofData;
|
|
79
77
|
};
|
|
80
|
-
export type SubmitLegacyTransactProofParams = {
|
|
81
|
-
chainType: string;
|
|
82
|
-
chainID: string;
|
|
83
|
-
txidVersion: TXIDVersion;
|
|
78
|
+
export type SubmitLegacyTransactProofParams = ChainParams & {
|
|
84
79
|
listKeys: string[];
|
|
85
80
|
legacyTransactProofDatas: LegacyTransactProofData[];
|
|
86
81
|
};
|
|
87
|
-
export type SubmitSingleCommitmentProofsParams = {
|
|
88
|
-
chainType: string;
|
|
89
|
-
chainID: string;
|
|
90
|
-
txidVersion: TXIDVersion;
|
|
82
|
+
export type SubmitSingleCommitmentProofsParams = ChainParams & {
|
|
91
83
|
singleCommitmentProofsData: SingleCommitmentProofsData;
|
|
92
84
|
};
|
|
93
85
|
export declare enum BlindedCommitmentType {
|
|
@@ -95,10 +87,7 @@ export declare enum BlindedCommitmentType {
|
|
|
95
87
|
Transact = "Transact",
|
|
96
88
|
Unshield = "Unshield"
|
|
97
89
|
}
|
|
98
|
-
export type ValidatePOIMerklerootsParams = {
|
|
99
|
-
chainType: string;
|
|
100
|
-
chainID: string;
|
|
101
|
-
txidVersion: TXIDVersion;
|
|
90
|
+
export type ValidatePOIMerklerootsParams = ChainParams & {
|
|
102
91
|
listKey: string;
|
|
103
92
|
poiMerkleroots: string[];
|
|
104
93
|
};
|
|
@@ -106,33 +95,20 @@ export type BlindedCommitmentData = {
|
|
|
106
95
|
blindedCommitment: string;
|
|
107
96
|
type: BlindedCommitmentType;
|
|
108
97
|
};
|
|
109
|
-
export type GetPOIsPerListParams = {
|
|
110
|
-
chainType: string;
|
|
111
|
-
chainID: string;
|
|
112
|
-
txidVersion: TXIDVersion;
|
|
98
|
+
export type GetPOIsPerListParams = ChainParams & {
|
|
113
99
|
listKeys: string[];
|
|
114
100
|
blindedCommitmentDatas: BlindedCommitmentData[];
|
|
115
101
|
};
|
|
116
|
-
export type GetMerkleProofsParams = {
|
|
117
|
-
chainType: string;
|
|
118
|
-
chainID: string;
|
|
119
|
-
txidVersion: TXIDVersion;
|
|
102
|
+
export type GetMerkleProofsParams = ChainParams & {
|
|
120
103
|
listKey: string;
|
|
121
104
|
blindedCommitments: string[];
|
|
122
105
|
};
|
|
123
|
-
export type ValidateTxidMerklerootParams = {
|
|
124
|
-
chainType: string;
|
|
125
|
-
chainID: string;
|
|
126
|
-
txidVersion: TXIDVersion;
|
|
106
|
+
export type ValidateTxidMerklerootParams = ChainParams & {
|
|
127
107
|
tree: number;
|
|
128
108
|
index: number;
|
|
129
109
|
merkleroot: string;
|
|
130
110
|
};
|
|
131
|
-
export type GetLatestValidatedRailgunTxidParams =
|
|
132
|
-
chainType: string;
|
|
133
|
-
chainID: string;
|
|
134
|
-
txidVersion: TXIDVersion;
|
|
135
|
-
};
|
|
111
|
+
export type GetLatestValidatedRailgunTxidParams = ChainParams;
|
|
136
112
|
export declare enum POIStatus {
|
|
137
113
|
Valid = "Valid",
|
|
138
114
|
ShieldBlocked = "ShieldBlocked",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proof-of-innocence.js","sourceRoot":"","sources":["../../src/models/proof-of-innocence.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"proof-of-innocence.js","sourceRoot":"","sources":["../../src/models/proof-of-innocence.ts"],"names":[],"mappings":";;;AA0CA,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,iCAAiB,CAAA;IACjB,qCAAqB,CAAA;IACrB,qCAAqB,CAAA;IACrB,iDAAiC,CAAA;AACnC,CAAC,EALW,YAAY,4BAAZ,YAAY,QAKvB;AAqDD,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,0CAAiB,CAAA;IACjB,8CAAqB,CAAA;IACrB,8CAAqB,CAAA;AACvB,CAAC,EAJW,qBAAqB,qCAArB,qBAAqB,QAIhC;AA8BD,IAAY,SASX;AATD,WAAY,SAAS;IACnB,6BAA6B;IAC7B,4BAAe,CAAA;IACf,iBAAiB;IACjB,4CAA+B,CAAA;IAC/B,2DAA2D;IAC3D,8CAAiC,CAAA;IACjC,sEAAsE;IACtE,gCAAmB,CAAA;AACrB,CAAC,EATW,SAAS,yBAAT,SAAS,QASpB;AAyCY,QAAA,sBAAsB,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,SAAS;AAC3C,QAAA,2BAA2B,GAAG,UAAU,CAAC;AACzC,QAAA,+BAA+B,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW;AACrD,QAAA,oCAAoC,GAAG,YAAY,CAAC;AAEjE,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,gCAAiB,CAAA;AACnB,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB;AASY,QAAA,kBAAkB,GAAc;IAC3C;QACE,GAAG,EAAE,kEAAkE;QACvE,IAAI,EAAE,WAAW,CAAC,MAAM;QACxB,IAAI,EAAE,gCAAgC;QACtC,WAAW,EACT,2KAA2K;KAC9K;CACF,CAAC;AAEF,IAAY,gBAmBX;AAnBD,WAAY,gBAAgB;IAC1B,mDAA+B,CAAA;IAC/B,iDAA6B,CAAA;IAC7B,sEAAkD,CAAA;IAClD,2DAAuC,CAAA;IACvC,wEAAoD,CAAA;IACpD,2DAAuC,CAAA;IACvC,8DAA0C,CAAA;IAC1C,sEAAkD,CAAA;IAClD,sEAAkD,CAAA;IAClD,sEAAkD,CAAA;IAClD,qFAAiE,CAAA;IACjE,yFAAqE,CAAA;IACrE,sDAAkC,CAAA;IAClC,iFAA6D,CAAA;IAC7D,uDAAmC,CAAA;IACnC,yDAAqC,CAAA;IACrC,4EAAwD,CAAA;IACxD,4EAAwD,CAAA;AAC1D,CAAC,EAnBW,gBAAgB,gCAAhB,gBAAgB,QAmB3B","sourcesContent":["import { TXIDVersion } from './engine';\nimport { NetworkName } from './network-config';\nimport { PreTransactionPOIsPerTxidLeafPerList } from './response-types';\n\n// TODO: Migrate to using Chain object directly when PPOI API update is permissioned\nexport type ChainParams = {\n chainType: string;\n chainID: string;\n txidVersion: TXIDVersion;\n};\n\nexport type TransactProofData = {\n snarkProof: SnarkProof;\n poiMerkleroots: string[];\n txidMerkleroot: string;\n txidMerklerootIndex: number;\n blindedCommitmentsOut: string[];\n railgunTxidIfHasUnshield: string;\n};\n\nexport type SnarkProof = {\n pi_a: [string, string];\n pi_b: [[string, string], [string, string]];\n pi_c: [string, string];\n};\n\nexport type MerkleProof = {\n leaf: string; // hash of commitment\n elements: string[];\n indices: string;\n root: string;\n};\n\nexport type ShieldQueueStatus = {\n unknown: number;\n pending: number;\n allowed: number;\n blocked: number;\n addedPOI: number;\n latestShield: Optional<string>;\n};\n\nexport enum POIEventType {\n Shield = 'Shield',\n Transact = 'Transact',\n Unshield = 'Unshield',\n LegacyTransact = 'LegacyTransact',\n}\n\nexport type POIEventLengths = Record<POIEventType, number>;\n\nexport type POIListStatus = {\n poiEventLengths: POIEventLengths;\n listProviderPOIEventQueueLength: Optional<number>;\n pendingTransactProofs: number;\n blockedShields: number;\n historicalMerklerootsLength: number;\n latestHistoricalMerkleroot: string;\n};\n\nexport type GetTransactProofsParams = ChainParams & {\n listKey: string;\n};\n\nexport type GetBlockedShieldsParams = ChainParams & {\n listKey: string;\n};\n\nexport type LegacyTransactProofData = {\n txidIndex: string;\n npk: string;\n value: string;\n tokenHash: string;\n blindedCommitment: string;\n};\n\nexport type SingleCommitmentProofsData = {\n commitment: string;\n npk: string;\n utxoTreeIn: number;\n utxoTreeOut: number;\n utxoPositionOut: number;\n railgunTxid: string;\n pois: PreTransactionPOIsPerTxidLeafPerList;\n};\n\nexport type SubmitTransactProofParams = ChainParams & {\n listKey: string;\n transactProofData: TransactProofData;\n};\n\nexport type SubmitLegacyTransactProofParams = ChainParams & {\n listKeys: string[];\n legacyTransactProofDatas: LegacyTransactProofData[];\n};\n\nexport type SubmitSingleCommitmentProofsParams = ChainParams & {\n singleCommitmentProofsData: SingleCommitmentProofsData;\n};\n\nexport enum BlindedCommitmentType {\n Shield = 'Shield',\n Transact = 'Transact',\n Unshield = 'Unshield',\n}\n\nexport type ValidatePOIMerklerootsParams = ChainParams & {\n listKey: string;\n poiMerkleroots: string[];\n};\n\nexport type BlindedCommitmentData = {\n blindedCommitment: string;\n type: BlindedCommitmentType;\n};\n\nexport type GetPOIsPerListParams = ChainParams & {\n listKeys: string[];\n blindedCommitmentDatas: BlindedCommitmentData[];\n};\n\nexport type GetMerkleProofsParams = ChainParams & {\n listKey: string;\n blindedCommitments: string[];\n};\n\nexport type ValidateTxidMerklerootParams = ChainParams & {\n tree: number;\n index: number;\n merkleroot: string;\n};\n\nexport type GetLatestValidatedRailgunTxidParams = ChainParams;\n\nexport enum POIStatus {\n // POI valdated in event list\n Valid = 'Valid',\n // Shield blocked\n ShieldBlocked = 'ShieldBlocked',\n // Transact/Unshield proof submitted, but not validated yet\n ProofSubmitted = 'ProofSubmitted',\n // Missing internal/external transact/unshield proof, or ShieldPending\n Missing = 'Missing',\n}\n\nexport type POIsPerList = {\n [listKey: string]: POIStatus;\n};\n\nexport type POIsPerListMap = {\n [blindedCommitment: string]: POIsPerList;\n};\n\nexport type TxidMerkletreeSyncStatus = {\n currentTxidIndex: number;\n currentMerkleroot: string;\n validatedTxidIndex: number;\n validatedMerkleroot: string;\n};\n\nexport type RailgunTxidStatus = {\n currentTxidIndex: Optional<number>;\n currentMerkleroot: Optional<string>;\n validatedTxidIndex: Optional<number>;\n validatedMerkleroot: Optional<string>;\n};\n\nexport type ValidatedRailgunTxidStatus = {\n validatedTxidIndex: Optional<number>;\n validatedMerkleroot: Optional<string>;\n};\n\nexport type NodeStatusAllNetworks = {\n listKeys: string[];\n forNetwork: Partial<Record<NetworkName, NodeStatusForNetwork>>;\n};\n\nexport type NodeStatusForNetwork = {\n txidStatus: RailgunTxidStatus;\n shieldQueueStatus: ShieldQueueStatus;\n listStatuses: Record<string, POIListStatus>;\n legacyTransactProofs: number;\n};\n\nexport const POI_SHIELD_PENDING_SEC = 60 * 60; // 1 hour\nexport const POI_SHIELD_PENDING_SEC_TEXT = 'One hour';\nexport const POI_SHIELD_PENDING_SEC_TEST_NET = 1 * 60; // 1 minute\nexport const POI_SHIELD_PENDING_SEC_TEST_NET_TEXT = 'One minute';\n\nexport enum POIListType {\n Active = 'Active',\n Gather = 'Gather',\n}\n\nexport type POIList = {\n key: string;\n type: POIListType;\n name: string;\n description: string;\n};\n\nexport const POI_REQUIRED_LISTS: POIList[] = [\n {\n key: 'efc6ddb59c098a13fb2b618fdae94c1c3a807abc8fb1837c93620c9143ee9e88',\n type: POIListType.Active,\n name: 'Chainalysis OFAC Sanctions API',\n description:\n 'API which is used to restrict bad actors designated by the US Department of the Treasury. See: https://www.chainalysis.com/free-cryptocurrency-sanctions-screening-tools.',\n },\n];\n\nexport enum POIJSONRPCMethod {\n NodeStatus = 'ppoi_node_status',\n POIEvents = 'ppoi_poi_events',\n POIMerkletreeLeaves = 'ppoi_poi_merkletree_leaves',\n TransactProofs = 'ppoi_transact_proofs',\n LegacyTransactProofs = 'ppoi_legacy_transact_proofs',\n BlockedShields = 'ppoi_blocked_shields',\n SubmitPOIEvents = 'ppoi_submit_poi_events',\n SubmitValidatedTXID = 'ppoi_submit_validated_txid',\n RemoveTransactProof = 'ppoi_remove_transact_proof',\n SubmitTransactProof = 'ppoi_submit_transact_proof',\n SubmitLegacyTransactProofs = 'ppoi_submit_legacy_transact_proofs',\n SubmitSingleCommitmentProofs = 'ppoi_submit_single_commitment_proofs',\n POIsPerList = 'ppoi_pois_per_list',\n POIsPerBlindedCommitment = 'ppoi_pois_per_blinded_commitment',\n MerkleProofs = 'ppoi_merkle_proofs',\n ValidatedTXID = 'ppoi_validated_txid',\n ValidateTXIDMerkleroot = 'ppoi_validate_txid_merkleroot',\n ValidatePOIMerkleroots = 'ppoi_validate_poi_merkleroots',\n}\n"]}
|
|
@@ -36,9 +36,17 @@ const getAvailableProviderJSONs = async (chainId, providerJsons, logError) => {
|
|
|
36
36
|
exports.getAvailableProviderJSONs = getAvailableProviderJSONs;
|
|
37
37
|
const getBlockNumber = async (chainId, provider, logError) => {
|
|
38
38
|
const network = ethers_1.Network.from(chainId);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
// Conditionally handle what type of provider is being passed
|
|
40
|
+
let rpcProvider;
|
|
41
|
+
// If URL starts with wss, use WebSocketProvider
|
|
42
|
+
if (provider.startsWith('wss')) {
|
|
43
|
+
rpcProvider = new ethers_1.WebSocketProvider(provider, network);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
rpcProvider = new ethers_1.JsonRpcProvider(provider, network, {
|
|
47
|
+
staticNetwork: network,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
42
50
|
try {
|
|
43
51
|
const block = await (0, promises_1.promiseTimeout)(rpcProvider.getBlock('latest'), BLOCK_NUMBER_TIMEOUT_MS);
|
|
44
52
|
if (block == null) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"available-rpc.js","sourceRoot":"","sources":["../../src/utils/available-rpc.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"available-rpc.js","sourceRoot":"","sources":["../../src/utils/available-rpc.ts"],"names":[],"mappings":"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","sourcesContent":["/// <reference types=\"../types/global\" />\nimport { JsonRpcProvider, Network, type Provider, WebSocketProvider } from 'ethers';\nimport { ProviderJson } from './fallback-provider';\nimport { getUpperBoundMedian } from './median';\nimport { promiseTimeout } from './promises';\n\ntype LogError = (err: string) => void;\n\nconst BLOCK_NUMBER_TIMEOUT_MS = 5000;\n\n/**\n * Health checks ProviderJson inputs, and returns an array of available RPC providers.\n * Available means that they respond to getBlockNumber(), and they are +/- 100 blocks from the median.\n */\nexport const getAvailableProviderJSONs = async (\n chainId: number,\n providerJsons: ProviderJson[],\n logError: LogError,\n): Promise<ProviderJson[]> => {\n const blockNumbers: Optional<number>[] = await Promise.all(\n providerJsons.map(\n async providerJson =>\n await getBlockNumber(chainId, providerJson.provider, logError),\n ),\n );\n\n const nonZeroBlockNumbers = blockNumbers.filter(\n blockNumber => blockNumber != null && blockNumber > 0,\n ) as number[];\n const medianBlockNumber = getUpperBoundMedian(nonZeroBlockNumbers);\n const lowerBoundRange = medianBlockNumber - 100;\n const upperBoundRange = medianBlockNumber + 100;\n\n return providerJsons.filter((providerJson, index) => {\n const blockNumber = blockNumbers[index];\n if (blockNumber == null) {\n logError(\n `RPC Health Check failed for ${providerJson.provider}: No Block Number`,\n );\n return false;\n }\n if (blockNumber < lowerBoundRange) {\n logError(\n `RPC Health Check failed for ${providerJson.provider}: Block Number -${\n medianBlockNumber - blockNumber\n } from median`,\n );\n return false;\n }\n if (blockNumber > upperBoundRange) {\n logError(\n `RPC Health Check failed for ${providerJson.provider}: Block Number +${\n blockNumber - medianBlockNumber\n } from median`,\n );\n return false;\n }\n return true;\n });\n};\n\nconst getBlockNumber = async (\n chainId: number,\n provider: string,\n logError: LogError,\n): Promise<Optional<number>> => {\n const network = Network.from(chainId);\n\n // Conditionally handle what type of provider is being passed\n let rpcProvider: Provider;\n\n // If URL starts with wss, use WebSocketProvider\n if(provider.startsWith('wss')) {\n rpcProvider = new WebSocketProvider(provider, network);\n } else {\n rpcProvider = new JsonRpcProvider(provider, network, {\n staticNetwork: network,\n });\n }\n\n try {\n const block = await promiseTimeout(\n rpcProvider.getBlock('latest'),\n BLOCK_NUMBER_TIMEOUT_MS,\n );\n if (block == null) {\n throw new Error('Block is null');\n }\n return block.number;\n } catch (cause) {\n if (!(cause instanceof Error)) {\n throw new Error('Non-error thrown from getBlockNumber', { cause });\n }\n rpcProvider.destroy();\n logError(cause.message);\n return undefined;\n }\n};\n"]}
|