UNPKG

originstamp-client-fetch

Version:
74 lines (58 loc) 2.77 kB
# TimestampApi example ## preparing ```bash import { TimestampApi } from "../apis"; import { Configuration } from "../runtime" import type { TimestampRequest, ProofRequest, TreeStatusRequest, TimestampResponse, TimestampData } from "../models"; ``` ## createTimestamp Submits a new hash to be timestamped. If the hash has not been submitted previously, a new timestamp will be created and and the associated tree returned. If the hash has already been submitted and a timestamp exists, the request will not create a new entry but will return the previously associated timestamp information with a 202 Accepted response. ```bash try { const config: Configuration = new Configuration({ apiKey: 'A valid API key' }); const api: TimestampApi = new TimestampApi(config); const request: TimestampRequest = { sha256: ["sha256_hash"] }; const response = await api.createTimestamp({ timestampRequest: request }); console.log("API called successfully. Returned data: ", response); } catch (error) { console.error(error); } ``` ## getProof Initiates a proof request for a previously submitted hash. This request does not return the proof immediately. If the transaction associated with the hash has been verified, the proof will be generated and delivered asynchronously via a pre-registered webhook. If the transaction has not yet been verified, the request will respond with 425 Too Early. You should not poll this endpoint for results. Instead, you must ensure that a webhook listener is available to receive the final proof. ```bash try { const config: Configuration = new Configuration({ apiKey: 'A valid API key' }); const api: TimestampApi = new TimestampApi(config); const request: ProofRequest = { sha256: ["sha256_hash"] }; await api.getProof({ proofRequest: request }); console.log("API called successfully."); } catch (error) { console.error(error); } ``` ## getTreeStatus Retrieves the submit status of the root node for the given tree. This endpoint allows clients to track the overall verification progress of all SHA-256 hashes aggregated under the same tree, instead of querying individual hash status. Trees represent batches of hashes that are bundled together before being submitted to a blockchain. The returned information includes the current submission status and timestamp details, if available. ```bash try { const config: Configuration = new Configuration({ apiKey: 'A valid API key' }); const api: TimestampApi = new TimestampApi(config); const treeId: string = "tree_id"; const status = await api.getTreeStatus({ treeId }); console.log("API called successfully. Returned data: ", status); } catch (error) { console.error(error); } ```