knitr::opts_chunk$set( eval = FALSE, echo = TRUE, cache = FALSE, comment = "" ) library(ROriginStamp) valid_key <- openssl::sha1(api_key()) == "4a0b1541d679c18ed81b2ee79052984cd6ab5597"
Before you can use the package, you have to get an API key from OriginStamp. For details, see their Get an API key documentation.
ROriginStamp
is momentarily only available on github, so you have to install it by using devtools:
if (!require(devtools)) { install.packages("devtools") library(devtools) } if (!require(ROriginStamp)) { devtools::install_github("rkrug/ROriginStamp") library(ROriginStamp) }
library(ROriginStamp)
This package is based on sha256 hashes as calculated by the openssl package by @opensslR as OriginStamp is using sha256 hashes.
The function hash(x)
is the workhorse for calculating hashes. It calculates sha256 from files. It returns an object of class hash
, which is simply a character vector of length 1 with the class hash
assigned.
The hash is calculated when
x
is a character vector,length(x)
is one, andx
points to an existing file.If you want to calculate the hash of an character vector of length one which is also a file name to an existing file,
hash(system.file("DESCRIPTION", package = "ROriginStamp"))
returns the hash of the file. This is identical to directly call the hash method which calculates the hash of the file:
hash_file(system.file("DESCRIPTION", package = "ROriginStamp"))
If you want to do anything more than hashing with this package, you have to register with OriginStamp and get an API key. You can register for a free account and still use all the functionality of this package. To get an API key is described in the Get an API key section of the documentation.
To make this key available to the package, you have to
Sys.setenv(ROriginStamp_api_key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
or
api_key()
function to set the api key by running api_key("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
or
key
argument.get_key_usage()
- Getting infomation about your OriginStamp accountTo get the key usage statistics is accomplished by using
get_key_usage()
This gives an overview over your usage of your credits. The actual numbers depend on the plan you are on and the number of credits used already.
For a detailed description of the return value see the Default«UsageResponse» in the models section of the API documentation.
get_currencies()
- Getting infomation about your OriginStamp accountOriginStamp can work with different blockchain based currencies. The list of the currencies supported can be retrieved by using
get_currencies()
For a detailed description of the return value see the DefaultOfListOfCurrencyModel in the models section of the API documentation.
create_timestamp()
- Create a new timestampLet's create a new timestamp.
As an example, let's create a dummy file contining a data.frame with 26 random numbers, to make sure, that the hash has not been timestamped by OriginStamp already.
tf <- tempfile() write.csv(data.frame(letters, LETTERS, 1:26, runif(26)), tf) create_timestamp( x = tf, comment = "This is a dummy test for creating a timestamp." )
Now let's submit the same hash again and see what happens:
create_timestamp( x = tf, comment = "This is a dummy test for creating a timestamp a second time." )
The difference is in $content$data$created
which is TRUE
when the submitted hash has not been timestamped already and subsequently created, and FALSE
when it already exists. This is an easy way to check if the submission was successful.
It is important to note, that the timestamps are not created immediately, but put in a cue, which is submitted at certain intervals, depending on the currency used. See the documentation on currencies for details.
get_hash_status()
- Getting the status of a submitted hashLet's get information about the status of some hashes submitted. We start with the status of the just submitted hash of obj
get_hash_status( x = tf )
Now lets look at the status of a hash submitted in the past and which is already processed and timestamped:
get_hash_status( x = as.hash("2c5d36be542f8f0e7345d77753a5d7ea61a443ba6a9a86bb060332ad56dba38e") )
The difference is in $content$data$timestamps
which is in the case of a submitted hash but not yet created timestamp an essentially empty table, while in the case of a created timestamp, a table lie=sting the timestamp information.
But this information is neither particularly useful, nor userfriendly if one wan's to proof the timestamp. For this, let's move the final command.
get_proof()
- Downloading proof of a created timestampThe structure of the command is very similar to the previous one, only that one can specify the type of the proof. This can be either in the form of a pdf
file (a 'certificate'), or as an xml file (a 'proof').
get_proof( x = as.hash("2c5d36be542f8f0e7345d77753a5d7ea61a443ba6a9a86bb060332ad56dba38e"), proof_type = "pdf" )
or
get_proof( x = as.hash("2c5d36be542f8f0e7345d77753a5d7ea61a443ba6a9a86bb060332ad56dba38e"), proof_type = "xml" )
The function returns an object containing the url where the document can be downloaded ($content$data$download_url
) which is automatically processed further and the document is downloaded. As file name, the argument file
is used. If it is not provided, the file name in the return value is used, which is of the format \code{proof.CURRENCY.HASH.xml} for \code{proof_type == "xml"} or \code{certificate.CURRENCY.HASH.pdf} for \code{proof_type == "pdf"}
To see the downloaded files, click here for the pdf or here for the xml.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.