Skip to content

Commit bce4d9f

Browse files
Update to RecordProvider Interface (#1074)
* wip: started upgrade to record provider interface and started record scanner implementation of said interface * moved record provider types to models dir. moved nonces out of record provider method signatures into RecordSearchParams interface. added jsdoc comments to record scanner * added jsdoc comments to record provider/scanner types * fixed failing record provider tests * fixed casing of fields on OwnedRecord and EncryptedRecord types * corrected fields in RecordsFilter interface * updated encryptedRecords function to mirror changes made to the endpoint in RSS * changed program to programs in RecordsFilter * fixed outdated test case for invalid transaction id API response * added optional apiKey field to RecordScanner * changed api key field on RecordScanner to be able to accept either a plain key as a string or an object containing the key and the header name * removed concrete record scanner impl * Add missing fields to documentation and objects Signed-off-by: Mike Turner <[email protected]> * corrected boolean type name in ownedFilter.ts --------- Signed-off-by: Mike Turner <[email protected]> Co-authored-by: Mike Turner <[email protected]>
1 parent e9e85dd commit bce4d9f

16 files changed

+699
-142
lines changed

sdk/src/browser.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { BlockJSON, Header, Metadata } from "./models/blockJSON.js";
66
import { ConfirmedTransactionJSON } from "./models/confirmed_transaction.js";
77
import { DeploymentJSON, VerifyingKeys } from "./models/deployment/deploymentJSON.js";
88
import { DeploymentObject } from "./models/deployment/deploymentObject.js";
9+
import { EncryptedRecord } from "./models/record-provider/encryptedRecord.js";
910
import { ExecutionJSON, FeeExecutionJSON } from "./models/execution/executionJSON.js";
1011
import { ExecutionObject, FeeExecutionObject } from "./models/execution/executionObject.js";
1112
import { FinalizeJSON } from "./models/finalizeJSON.js";
@@ -15,6 +16,8 @@ import { InputJSON } from "./models/input/inputJSON.js";
1516
import { InputObject } from "./models/input/inputObject.js";
1617
import { OutputJSON } from "./models/output/outputJSON.js";
1718
import { OutputObject } from "./models/output/outputObject.js";
19+
import { OwnedFilter } from "./models/record-scanner/ownedFilter.js";
20+
import { OwnedRecord } from "./models/record-provider/ownedRecord.js";
1821
import { OwnerJSON } from "./models/owner/ownerJSON.js";
1922
import { PlaintextArray} from "./models/plaintext/array.js";
2023
import { PlaintextLiteral} from "./models/plaintext/literal.js";
@@ -23,6 +26,9 @@ import { PlaintextStruct} from "./models/plaintext/struct.js";
2326
import { ProvingRequestJSON } from "./models/provingRequest.js";
2427
import { ProvingResponse } from "./models/provingResponse.js";
2528
import { RatificationJSON } from "./models/ratification.js";
29+
import { RecordsFilter } from "./models/record-scanner/recordsFilter.js";
30+
import { RecordsResponseFilter } from "./models/record-scanner/recordsResponseFilter.js";
31+
import { RecordSearchParams } from "./models/record-provider/recordSearchParams.js";
2632
import { SolutionsJSON, SolutionJSON, PartialSolutionJSON } from "./models/solution.js";
2733
import { TransactionJSON } from "./models/transaction/transactionJSON.js";
2834
import { TransactionObject } from "./models/transaction/transactionObject.js";
@@ -45,7 +51,6 @@ import {
4551
BlockHeightSearch,
4652
NetworkRecordProvider,
4753
RecordProvider,
48-
RecordSearchParams,
4954
} from "./record-provider.js";
5055

5156
// @TODO: This function is no longer needed, remove it.
@@ -136,6 +141,7 @@ export {
136141
ConfirmedTransactionJSON,
137142
DeploymentJSON,
138143
DeploymentObject,
144+
EncryptedRecord,
139145
ExecutionJSON,
140146
ExecutionObject,
141147
FeeExecutionJSON,
@@ -156,6 +162,8 @@ export {
156162
OfflineSearchParams,
157163
OutputJSON,
158164
OutputObject,
165+
OwnedFilter,
166+
OwnedRecord,
159167
OwnerJSON,
160168
PartialSolutionJSON,
161169
PlaintextArray,
@@ -166,6 +174,8 @@ export {
166174
ProvingRequestJSON,
167175
ProvingResponse,
168176
RatificationJSON,
177+
RecordsFilter,
178+
RecordsResponseFilter,
169179
RecordProvider,
170180
RecordSearchParams,
171181
SolutionJSON,
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Encrypted Record found on chain. This type provides the record ciphertext and metadata from the ledger such as the record's name, the program/function that produced it, etc.
3+
*
4+
* @property {string} commitment - The commitment of the record.
5+
* @property {string | undefined} checksum - The checksum of the record.
6+
* @property {number | undefined} block_height - The block height of the record.
7+
* @property {number | undefined} block_timestamp - The block timestamp of the record.
8+
* @property {string | undefined} program_name - The name of the program that produced the record.
9+
* @property {string | undefined} function_name - The name of the function that produced the record.
10+
* @property {number | undefined} output_index - The output index of the record.
11+
* @property {string | undefined} owner - The owner of the record.
12+
* @property {string | undefined} record_ciphertext - The ciphertext of the record.
13+
* @property {string | undefined} record_name - The name of the record.
14+
* @property {string | undefined} record_nonce - The nonce of the record.
15+
* @property {string | undefined} sender_ciphertext - The ciphertext of the sender.
16+
* @property {string | undefined} transaction_id - The ID of the transaction that produced the record.
17+
* @property {string | undefined} transition_id - The ID of the transition that produced the record.
18+
* @property {number | undefined} transaction_index - The index of the transaction that produced the record.
19+
* @property {number | undefined} transition_index - The index of the transition that produced the record.
20+
*
21+
* @example
22+
* const encryptedRecord: EncryptedRecord = {
23+
* commitment: "1754131901135854615627743152473414463769543922079966020586765988138574911385field",
24+
* checksum: "731623304764338277682996290553427512270277231686866672455141481050283829616field",
25+
* block_height: 123456,
26+
* block_timestamp: 1725845998,
27+
* program_name: "credits.aleo",
28+
* function_name: "transfer_private",
29+
* output_index: 0,
30+
* owner: "ciphertext1qgqdetlfzk98jkm4e7sgqml66e3x2gpg5d6udkpw0g67z0tplkpmzrm6q5dyfd7xhgmhedvptxzwfhrtxaqn7n0hs0esge3lwg9s2zukqgzxd0cr",
31+
* record_ciphertext: "record1qyqsqt43u9kp97svljyyup3v4jmppd0vgght9edvvmtxx6mxycsej8cwqsrxzmt0w4h8ggcqqgqspf8zqut2ycnap7f0uzz5ktu0cxscca96urtkg2aweuzn70787dsrpp6x76m9de0kjezrqqpqyqp3mn3xeh53lukvcy406amjf5g0ksl3saauzjk0j4ljtjqq6kqlqhdz05sw92zye96qym7kp83ra0eesgtwhaw37c85r499456se8ts28m90p6x2unwv9k97ct4w35x7unf0fshg6t0de0hyet3w45hyetyyvqqyqgq4t2wr9tmcrfha5tfz5j585ptvvslqe0f6sf29vytshhdh7ym05rpqct4w35x7unf0fjkghm4de6xjmprqqpqzqru6p7fef29vuz6smyqwcn3z7jhxtdgjdw5xv23ppxhpgnvu72fp8hz6fjt6gsdn8yxhzq7gpsah0rscwqrzxwl5e8aemkj5gt09y7q5506yrf",
32+
* record_name: "credits",
33+
* record_nonce: "3077450429259593211617823051143573281856129402760267155982965992208217472983group",
34+
* sender_ciphertext: "1754131901135854615627743152473414463769543922079966020586765988138574911385field",
35+
* transaction_id: "at1f8ueqxu3x49sckpc6jlg676tmxumddzer3fwe2l0dxwj4dqxygyqua4u2q",
36+
* transition_id: "au17mm5v7sfwus6y40xsyc99d5rtsr4vsajdec6twdjzv0m458q85zspqdnka",
37+
* transaction_index: 0,
38+
* transition_index: 0,
39+
* }
40+
*/
41+
export type EncryptedRecord = {
42+
commitment: string;
43+
checksum?: string;
44+
block_height?: number;
45+
block_timestamp?: number;
46+
program_name?: string;
47+
function_name?: string;
48+
output_index?: number;
49+
owner?: string;
50+
record_ciphertext?: string;
51+
record_name?: string;
52+
record_nonce?: string;
53+
sender_ciphertext?: string;
54+
transaction_id?: string;
55+
transition_id?: string;
56+
transaction_index?: number;
57+
transition_index?: number;
58+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Record owned by a registered view key. This type provides the record ciphertext, record plaintext and metadata from the ledger such as the record's name, the program/function that produced it, etc.
3+
*
4+
* @property {number | undefined} block_height - Block height where the record was created.
5+
* @property {number | undefined} block_timestamp - The timestamp of the block that the record was created in.
6+
* @property {string | undefined} commitment - Commitment of the record.
7+
* @property {string | undefined} function_name - Name of the function that created the record.
8+
* @property {number | undefined} output_index - Index of the output in the function call that created the record.
9+
* @property {string | undefined} owner - Address of the record owner.
10+
* @property {string | undefined} program_name - Name of the program that created the record.
11+
* @property {string | undefined} record_ciphertext - Encrypted ciphertext of the record.
12+
* @property {string | undefined} record_name - Name of the record.
13+
* @property {string | undefined} sender - Address of the sender.
14+
* @property {boolean | undefined} spent - Whether the record has been spent.
15+
* @property {string | undefined} tag - Tag associated with the record.
16+
* @property {string | undefined} transaction_id - ID of the transaction that created the record.
17+
* @property {string | undefined} transition_id - ID of the transition that created the record.
18+
* @property {string | undefined} transaction_index - Index of the transaction in the block.
19+
* @property {string | undefined} transition_index - Index of the transition in the transaction.
20+
*
21+
* @example
22+
* const ownedRecord: OwnedRecord = {
23+
* block_height: 123456,
24+
* block_timestamp: 1725845998,
25+
* commitment: "1754131901135854615627743152473414463769543922079966020586765988138574911385field",
26+
* function_name: "transfer_public_to_private",
27+
* output_index: 0,
28+
* owner: "ciphertext1qgqdetlfzk98jkm4e7sgqml66e3x2gpg5d6udkpw0g67z0tplkpmzrm6q5dyfd7xhgmhedvptxzwfhrtxaqn7n0hs0esge3lwg9s2zukqgzxd0cr",
29+
* program_name: "credits.aleo",
30+
* record_ciphertext: "record1qyqsqt43u9kp97svljyyup3v4jmppd0vgght9edvvmtxx6mxycsej8cwqsrxzmt0w4h8ggcqqgqspf8zqut2ycnap7f0uzz5ktu0cxscca96urtkg2aweuzn70787dsrpp6x76m9de0kjezrqqpqyqp3mn3xeh53lukvcy406amjf5g0ksl3saauzjk0j4ljtjqq6kqlqhdz05sw92zye96qym7kp83ra0eesgtwhaw37c85r499456se8ts28m90p6x2unwv9k97ct4w35x7unf0fshg6t0de0hyet3w45hyetyyvqqyqgq4t2wr9tmcrfha5tfz5j585ptvvslqe0f6sf29vytshhdh7ym05rpqct4w35x7unf0fjkghm4de6xjmprqqpqzqru6p7fef29vuz6smyqwcn3z7jhxtdgjdw5xv23ppxhpgnvu72fp8hz6fjt6gsdn8yxhzq7gpsah0rscwqrzxwl5e8aemkj5gt09y7q5506yrf",
31+
* record_plaintext: "{ owner: aleo1j7qxyunfldj2lp8hsvy7mw5k8zaqgjfyr72x2gh3x4ewgae8v5gscf5jh3.private, microcredits: 1500000000000000u64.private, _nonce: 3077450429259593211617823051143573281856129402760267155982965992208217472983group.public , _version: 1u8 }",
32+
* record_name: "credits",
33+
* spent: true,
34+
* sender: "aleo1sf5kk4f8mcmgjasw9fannmm0h8z2nwqxu5e200cjneu28jxvtvpqulfxsa",
35+
* tag: "6511661650536816422260305447175136877451468301541296257226129781611237851030field",
36+
* transaction_id: "at1f8ueqxu3x49sckpc6jlg676tmxumddzer3fwe2l0dxwj4dqxygyqua4u2q",
37+
* transition_id: "au17mm5v7sfwus6y40xsyc99d5rtsr4vsajdec6twdjzv0m458q85zspqdnka",
38+
* transaction_index: 0,
39+
* transition_index: 0,
40+
* }
41+
*/
42+
export type OwnedRecord = {
43+
block_height?: number;
44+
block_timestamp?: number;
45+
commitment?: string;
46+
function_name?: string;
47+
output_index?: number;
48+
owner?: string;
49+
program_name?: string;
50+
record_ciphertext?: string;
51+
record_plaintext?: string;
52+
record_name?: string;
53+
sender?: string;
54+
spent?: boolean;
55+
tag?: string;
56+
transaction_id?: string;
57+
transition_id?: string;
58+
transaction_index?: number;
59+
transition_index?: number;
60+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Interface for record search parameters. This allows for arbitrary search parameters to be passed to record provider
3+
* implementations.
4+
*
5+
* @example
6+
* const recordSearchParams: RecordSearchParams = {
7+
* // Declared fields
8+
* unspent: true,
9+
* nonces: ["3077450429259593211617823051143573281856129402760267155982965992208217472983group"],
10+
* // Arbitrary fields
11+
* startHeight: 123456,
12+
* programName: "credits.aleo"
13+
* }
14+
*/
15+
export interface RecordSearchParams {
16+
unspent?: boolean;
17+
nonces?: string[];
18+
[key: string]: any; // This allows for arbitrary keys with any type values
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { RecordSearchParams } from "../record-provider/recordSearchParams";
2+
import { RecordsFilter } from "./recordsFilter";
3+
import { OwnedRecordsResponseFilter } from "./ownedRecordsResponseFilter";
4+
5+
/**
6+
* OwnedFilter is an extension of RecordSearchParams that represents a filter for scanning owned records.
7+
*
8+
* @example
9+
* const ownedFilter: OwnedFilter = {
10+
* unspent: true,
11+
* nonces: ["3077450429259593211617823051143573281856129402760267155982965992208217472983group"],
12+
* decrypt: true,
13+
* filter: {
14+
* program: "credits.aleo",
15+
* record: "credits",
16+
* },
17+
* }
18+
*/
19+
export interface OwnedFilter extends RecordSearchParams {
20+
decrypt?: boolean;
21+
filter?: RecordsFilter;
22+
responseFilter?: OwnedRecordsResponseFilter;
23+
unspent?: boolean;
24+
uuid?: string;
25+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* OwnedRecordsResponseFilter is a type that represents a filter for the response from a record provider.
3+
* A `true` value for a field in the filter will include that field in the response.
4+
*
5+
* @example
6+
* const ownedRecordsResponseFilter: OwnedRecordsResponseFilter = {
7+
* commitment: true,
8+
* owner: true,
9+
* tag: true,
10+
* sender: true,
11+
* spent: true,
12+
* record_ciphertext: true,
13+
* block_height: true,
14+
* block_timestamp: true,
15+
* output_index: true,
16+
* record_name: true,
17+
* function_name: true,
18+
* program_name: true,
19+
* transition_id: true,
20+
* transaction_id: true,
21+
* transaction_index: true,
22+
* transition_index: true,
23+
* }
24+
*/
25+
export interface OwnedRecordsResponseFilter {
26+
commitment?: boolean;
27+
owner?: boolean;
28+
tag?: boolean;
29+
sender?: boolean;
30+
spent?: boolean;
31+
record_ciphertext?: boolean;
32+
block_height?: boolean;
33+
block_timestamp?: boolean;
34+
output_index?: boolean;
35+
record_name?: boolean;
36+
function_name?: boolean;
37+
program_name?: boolean;
38+
transition_id?: boolean;
39+
transaction_id?: boolean;
40+
transaction_index?: boolean;
41+
transition_index?: boolean;
42+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { RecordSearchParams } from "../record-provider/recordSearchParams";
2+
import { RecordsResponseFilter } from "./recordsResponseFilter";
3+
4+
/**
5+
* RecordsFilter is an extension of RecordSearchParams that represents a filter for scanning encrypted or owned records.
6+
*
7+
* @example
8+
* const recordsFilter: RecordsFilter = {
9+
* start: 0,
10+
* end: 100,
11+
* programs: ["credits.aleo"],
12+
* records: ["credits"],
13+
* functions: ["transfer_public_to_private"],
14+
* response: {
15+
* program: true,
16+
* record: true,
17+
* function: true,
18+
* transition: true,
19+
* block_height: true,
20+
* transaction_id: true,
21+
* }
22+
* results_per_page: 100,
23+
* page: 0,
24+
* }
25+
*/
26+
export interface RecordsFilter extends RecordSearchParams {
27+
commitments?: string[];
28+
response?: RecordsResponseFilter;
29+
start?: number;
30+
end?: number;
31+
programs?: string[];
32+
records?: string[];
33+
functions?: string[];
34+
results_per_page?: number;
35+
page?: number;
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* RecordsResponseFilter is a type that represents a filter for the response from a record provider.
3+
* A `true` value for a field in the filter will include that field in the response.
4+
*
5+
* @example
6+
* const recordsResponseFilter: RecordsResponseFilter = {
7+
* block_height: true,
8+
* checksum: true,
9+
* commitment: true,
10+
* record_ciphertext: true,
11+
* function_name: true,
12+
* nonce: true,
13+
* output_index: true,
14+
* owner: true,
15+
* program_name: true,
16+
* record_name: true,
17+
* transaction_id: true,
18+
* transition_id: true,
19+
* transaction_index: true,
20+
* transition_index: true,
21+
* }
22+
*/
23+
export type RecordsResponseFilter = {
24+
blockHeight?: boolean;
25+
checksum?: boolean;
26+
commitment?: boolean;
27+
record_ciphertext?: boolean;
28+
function_name?: boolean;
29+
nonce?: boolean;
30+
output_index?: boolean;
31+
owner?: boolean;
32+
program_name?: boolean;
33+
record_name?: boolean;
34+
transaction_id?: boolean;
35+
transition_id?: boolean;
36+
transaction_index?: boolean;
37+
transition_index?: boolean;
38+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* RegistrationRequest is a type that represents a request to register an account's view key with a record scanning service.
3+
*
4+
* @example
5+
* const registrationRequest: RegistrationRequest = {
6+
* view_key: "AViewKey1ccEt8A2Ryva5rxnKcAbn7wgTaTsb79tzkKHFpeKsm9NX",
7+
* start: 123456,
8+
* }
9+
*/
10+
export type RegistrationRequest = {
11+
view_key: string;
12+
start: number;
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* RegistrationResponse is a type that represents a response from a record scanning service.
3+
*
4+
* @example
5+
* const registrationResponse: RegistrationResponse = {
6+
* uuid: "5291249998620209321712738612705518874926462927543783711572375085855029172391field",
7+
* job_id: "3019177021147406178755252788128212930359855601860174268911518336835545087409field",
8+
* status: "pending",
9+
* }
10+
*/
11+
interface RegistrationResponse {
12+
uuid: string,
13+
job_id?: string,
14+
status?: string
15+
}

0 commit comments

Comments
 (0)