Prerequisites

Before you can use the package, you have to get an API key from OriginStamp. For details, see their Get an API key documentation.

Installation

ROriginStamp is momentarily only available on github, so you have to install it by using devtools:

if (!require(devtools)) {
  install.packages("devtools")
  library(devtools)
}
devtools::install_github("rkrug/ROriginStamp")

How to use it

Hashing

This package is based on sha256 hashes as calculated by the openssl package by Ooms (2020) as OriginStamp is using sha256 hashes.

The function hash(x) is the workhorse for calculating hashes. It calculates sha256 from R objects as well as, 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

  1. x is a character vector,
  2. if the length(x) is one, and
  3. x 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"))

Create sha356 hash from R file x [/private/var/folders/50/wcr5bjwn75q595n6x82gxj280000gq/T/RtmpBkcx2Y/temp_libpathd0c20fc5a9f/ROriginStamp/DESCRIPTION]
sha256 af:69:1f:06:ee:50:03:18:22:9c:00:13:ed:57:00:ed:e1:bb:11:09:19:30:13:92:64:9a:2e:8d:d0:43:5d:1e 

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"))

Create sha356 hash from R file x [/private/var/folders/50/wcr5bjwn75q595n6x82gxj280000gq/T/RtmpBkcx2Y/temp_libpathd0c20fc5a9f/ROriginStamp/DESCRIPTION]
sha256 af:69:1f:06:ee:50:03:18:22:9c:00:13:ed:57:00:ed:e1:bb:11:09:19:30:13:92:64:9a:2e:8d:d0:43:5d:1e 

If you want to calculate the hash of the actual R object, you have to method which handles all R objects:

hash.default(system.file("DESCRIPTION", package = "ROriginStamp"))

Create sha356 hash from R object x
sha256 6b:a3:48:5d:43:d0:44:73:88:ba:0b:69:59:52:a3:10:4a:4b:f3:37:d1:e0:e3:6f:b8:70:87:a1:0d:c7:e9:6a 

If x is an object of class hash, the object x is returned as is:

identical( 
  hash(letters), 
  hash(hash(letters))
)

Create sha356 hash from R object x

Create sha356 hash from R object x

x is already a hash - returning x unprocessed
[1] TRUE

Provide API Key to the Functions

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

  1. either set it as an environmental variable, by e.g. using
Sys.setenv(ROriginStamp_api_key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")

or

  1. use the api_key() function to set the api key by running
api_key("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")`

or

  1. specify it in each call by using the key argument.

get_key_usage() - Getting infomation about your OriginStamp account

To get the key usage statistics is accomplished by using

$status
[1] 200

$content
$content$error_code
[1] 0

$content$error_message
NULL

$content$data
$content$data$credits_per_month
[1] 6000

$content$data$remaining_credits
[1] 5199.5

$content$data$consumed_credits
[1] 800.5

$content$data$timestamps_per_month
[1] 1000

$content$data$consumed_timestamps
[1] 19

$content$data$certificate_per_month
[1] 1000

$content$data$consumed_certificates
[1] 201

$content$data$limitation_type
[1] 1



$headers
$headers[[1]]
 [1] "HTTP/2 200 "                                                                                                                                                                                                                                      
 [2] "date: Fri, 26 Mar 2021 09:58:11 GMT"                                                                                                                                                                                                              
 [3] "content-type: application/json;charset=UTF-8"                                                                                                                                                                                                     
 [4] "set-cookie: __cfduid=d9023052446c223442a143cd11c5aae131616752691; expires=Sun, 25-Apr-21 09:58:11 GMT; path=/; domain=.originstamp.com; HttpOnly; SameSite=Lax"                                                                                   
 [5] "x-content-type-options: nosniff"                                                                                                                                                                                                                  
 [6] "x-xss-protection: 1; mode=block"                                                                                                                                                                                                                  
 [7] "cache-control: no-cache, no-store, max-age=0, must-revalidate"                                                                                                                                                                                    
 [8] "pragma: no-cache"                                                                                                                                                                                                                                 
 [9] "expires: 0"                                                                                                                                                                                                                                       
[10] "x-frame-options: DENY"                                                                                                                                                                                                                            
[11] "cf-cache-status: DYNAMIC"                                                                                                                                                                                                                         
[12] "cf-request-id: 090f91616c0000dfe315b75000000001"                                                                                                                                                                                                  
[13] "expect-ct: max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""                                                                                                                                             
[14] "report-to: {\"group\":\"cf-nel\",\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report?s=4zJb4RnqPLNrsQm5lJIz8gdOFUsjWfR0IJygRE3KwARmdtmQ8tZz443phJG808Iy4YpAwCtdom0ZVjrSJs6LoueD0RAPAtZ65Ums%2B5LHn7aGxNUP\"}],\"max_age\":604800}"
[15] "nel: {\"report_to\":\"cf-nel\",\"max_age\":604800}"                                                                                                                                                                                               
[16] "server: cloudflare"                                                                                                                                                                                                                               
[17] "cf-ray: 635f84e24cf5dfe3-FRA"                                                                                                                                                                                                                     
[18] "content-encoding: gzip"                                                                                                                                                                                                                           
[19] ""                                                                                                                                                                                                                                                 


attr(,"class")
[1] "OriginStampResponse"

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 account

OriginStamp can work with different blockchain based currencies. The list of the currencies supported can be retrieved by using

$status
[1] 200

$content
$content$error_code
[1] 0

$content$error_message
NULL

$content$data
  currency_id   currency
1           0    BITCOIN
2           1   ETHEREUM
3           2       AION
4         100 SUEDKURIER


$headers
$headers[[1]]
 [1] "HTTP/2 200 "                                                                                                                                                                                                                                                  
 [2] "date: Fri, 26 Mar 2021 09:58:11 GMT"                                                                                                                                                                                                                          
 [3] "content-type: application/json;charset=UTF-8"                                                                                                                                                                                                                 
 [4] "set-cookie: __cfduid=d9023052446c223442a143cd11c5aae131616752691; expires=Sun, 25-Apr-21 09:58:11 GMT; path=/; domain=.originstamp.com; HttpOnly; SameSite=Lax"                                                                                               
 [5] "cf-cache-status: DYNAMIC"                                                                                                                                                                                                                                     
 [6] "cf-request-id: 090f9161ff0000dfe30eadd000000001"                                                                                                                                                                                                              
 [7] "expect-ct: max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""                                                                                                                                                         
 [8] "report-to: {\"group\":\"cf-nel\",\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report?s=HwH%2BWkaxelhCyhN%2BcesZPslm2kBbBA0xwAGoH%2FV6zlKj%2B0u6cl4r9VrGryH9zu7VldIkeLMm43t3z%2BUGPefReLGUkQHHpfNlbJ5c%2Bdcw%2F5f4A5jd\"}],\"max_age\":604800}"
 [9] "nel: {\"report_to\":\"cf-nel\",\"max_age\":604800}"                                                                                                                                                                                                           
[10] "server: cloudflare"                                                                                                                                                                                                                                           
[11] "cf-ray: 635f84e33dd7dfe3-FRA"                                                                                                                                                                                                                                 
[12] "content-encoding: gzip"                                                                                                                                                                                                                                       
[13] ""                                                                                                                                                                                                                                                             


attr(,"class")
[1] "OriginStampResponse"

For a detailed description of the return value see the DefaultOfListOfCurrencyModel in the models section of the API documentation.

create_timestamp() - Create a new timestamp

Let’s create a new timestamp.

As an example, let’s create a timestamp for 100 random numbers, to make sure, that the hash has not been timestamped by OriginStamp already.

obj <- runif(100)
create_timestamp(
  x = obj, 
  comment = "This is a dummy test for creating a timestamp."
)

Create sha356 hash from R object x
$status
[1] 200

$content
$content$error_code
[1] 0

$content$error_message
NULL

$content$data
$content$data$created
[1] TRUE

$content$data$date_created
[1] 1.616753e+12

$content$data$comment
[1] "This is a dummy test for creating a timestamp."

$content$data$hash_string
[1] "8ffa738c77fc3e9e0c7321e06adc0b6ed2301f0a28d5c064fcb9b3fe68c6a564"

$content$data$timestamps
  currency_id transaction private_key timestamp submit_status
1           0          NA          NA        NA             0
2           1          NA          NA        NA             0
3           2          NA          NA        NA             0
4         100          NA          NA        NA             0



$headers
$headers[[1]]
 [1] "HTTP/2 200 "                                                                                                                                                                                                                                      
 [2] "date: Fri, 26 Mar 2021 09:58:12 GMT"                                                                                                                                                                                                              
 [3] "content-type: application/json;charset=UTF-8"                                                                                                                                                                                                     
 [4] "set-cookie: __cfduid=d9023052446c223442a143cd11c5aae131616752691; expires=Sun, 25-Apr-21 09:58:11 GMT; path=/; domain=.originstamp.com; HttpOnly; SameSite=Lax"                                                                                   
 [5] "cf-cache-status: DYNAMIC"                                                                                                                                                                                                                         
 [6] "cf-request-id: 090f9162e70000dfe3080f6000000001"                                                                                                                                                                                                  
 [7] "expect-ct: max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""                                                                                                                                             
 [8] "report-to: {\"group\":\"cf-nel\",\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report?s=SwYAj1ig%2Bq7fSHu7PHODS1qZPCvB88yYXnRuTErMSexrJgySxFi2F2ADZwCUMYlrfPbgTGQYpYrKk0vC5zjIvXby1n7ArCpB5Hs84QFtleRvhQ6Y\"}],\"max_age\":604800}"
 [9] "nel: {\"report_to\":\"cf-nel\",\"max_age\":604800}"                                                                                                                                                                                               
[10] "server: cloudflare"                                                                                                                                                                                                                               
[11] "cf-ray: 635f84e4af5edfe3-FRA"                                                                                                                                                                                                                     
[12] "content-encoding: gzip"                                                                                                                                                                                                                           
[13] ""                                                                                                                                                                                                                                                 


attr(,"class")
[1] "OriginStampResponse"

Now let’s submit the same hash again and see what happens:

create_timestamp(
  x = obj, 
  comment = "This is a dummy test for creating a timestamp a second time."
)

Create sha356 hash from R object x
$status
[1] 200

$content
$content$error_code
[1] 0

$content$error_message
NULL

$content$data
$content$data$created
[1] FALSE

$content$data$date_created
[1] 1.616753e+12

$content$data$comment
[1] "This is a dummy test for creating a timestamp a second time."

$content$data$hash_string
[1] "8ffa738c77fc3e9e0c7321e06adc0b6ed2301f0a28d5c064fcb9b3fe68c6a564"

$content$data$timestamps
  currency_id transaction private_key timestamp submit_status
1           0          NA          NA        NA             0
2           1          NA          NA        NA             0
3           2          NA          NA        NA             0
4         100          NA          NA        NA             0



$headers
$headers[[1]]
 [1] "HTTP/2 200 "                                                                                                                                                                                                                                            
 [2] "date: Fri, 26 Mar 2021 09:58:12 GMT"                                                                                                                                                                                                                    
 [3] "content-type: application/json;charset=UTF-8"                                                                                                                                                                                                           
 [4] "set-cookie: __cfduid=d298633c6091d0bc7d02df837b7ac41c61616752692; expires=Sun, 25-Apr-21 09:58:12 GMT; path=/; domain=.originstamp.com; HttpOnly; SameSite=Lax"                                                                                         
 [5] "cf-cache-status: DYNAMIC"                                                                                                                                                                                                                               
 [6] "cf-request-id: 090f91654a0000dfe312809000000001"                                                                                                                                                                                                        
 [7] "expect-ct: max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""                                                                                                                                                   
 [8] "report-to: {\"group\":\"cf-nel\",\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report?s=1e4NtE0A%2F0WoAqBh3LCQz2JcEgnCkTQC3zeDpbyyVV1hIHl0yY0%2B%2B47%2BEPu8FvFYaheNQVc0L8zDm8s97JpYJzOv5mS5jmfstF1n5mEi3A1hbfXh\"}],\"max_age\":604800}"
 [9] "nel: {\"report_to\":\"cf-nel\",\"max_age\":604800}"                                                                                                                                                                                                     
[10] "server: cloudflare"                                                                                                                                                                                                                                     
[11] "cf-ray: 635f84e87c2adfe3-FRA"                                                                                                                                                                                                                           
[12] "content-encoding: gzip"                                                                                                                                                                                                                                 
[13] ""                                                                                                                                                                                                                                                       


attr(,"class")
[1] "OriginStampResponse"

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 bash cue, which is submitted at certain intervalls, depending on the currency used. See the documentation on currencies for details.

get_hash_status() - Getting the status of a submitted hash

Let’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 = obj
)

Create sha356 hash from R object x
$status
[1] 200

$content
$content$error_code
[1] 0

$content$error_message
NULL

$content$data
$content$data$created
[1] FALSE

$content$data$date_created
[1] 1.616753e+12

$content$data$comment
[1] "This is a dummy test for creating a timestamp."

$content$data$hash_string
[1] "8ffa738c77fc3e9e0c7321e06adc0b6ed2301f0a28d5c064fcb9b3fe68c6a564"

$content$data$timestamps
  currency_id transaction private_key timestamp submit_status
1           0          NA          NA        NA             0
2           1          NA          NA        NA             0
3           2          NA          NA        NA             0
4         100          NA          NA        NA             0



$headers
$headers[[1]]
 [1] "HTTP/2 200 "                                                                                                                                                                                                                                        
 [2] "date: Fri, 26 Mar 2021 09:58:12 GMT"                                                                                                                                                                                                                
 [3] "content-type: application/json;charset=UTF-8"                                                                                                                                                                                                       
 [4] "set-cookie: __cfduid=d298633c6091d0bc7d02df837b7ac41c61616752692; expires=Sun, 25-Apr-21 09:58:12 GMT; path=/; domain=.originstamp.com; HttpOnly; SameSite=Lax"                                                                                     
 [5] "cf-cache-status: DYNAMIC"                                                                                                                                                                                                                           
 [6] "cf-request-id: 090f9166120000dfe360242000000001"                                                                                                                                                                                                    
 [7] "expect-ct: max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""                                                                                                                                               
 [8] "report-to: {\"group\":\"cf-nel\",\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report?s=HfkUgRmTAGtoCK02SqTmu7x8inTezJtr0f1gCbgGUr3TAESnbLPb95%2B5UUv4eKuzD75Ud3vhwoTh4Non20KxSUojl9ugQ5gg%2BVyIGZzEdm0tedW9\"}],\"max_age\":604800}"
 [9] "nel: {\"report_to\":\"cf-nel\",\"max_age\":604800}"                                                                                                                                                                                                 
[10] "server: cloudflare"                                                                                                                                                                                                                                 
[11] "cf-ray: 635f84e9bd9adfe3-FRA"                                                                                                                                                                                                                       
[12] "content-encoding: gzip"                                                                                                                                                                                                                             
[13] ""                                                                                                                                                                                                                                                   


attr(,"class")
[1] "OriginStampResponse"

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")
)

x is already a hash - returning x unprocessed
$status
[1] 200

$content
$content$error_code
[1] 0

$content$error_message
NULL

$content$data
$content$data$created
[1] FALSE

$content$data$date_created
[1] 1.541203e+12

$content$data$comment
[1] "test"

$content$data$hash_string
[1] "2c5d36be542f8f0e7345d77753a5d7ea61a443ba6a9a86bb060332ad56dba38e"

$content$data$timestamps
  currency_id                                                      transaction
1           0 aed3db9ef94953f65e93d56a4e5bcf234d43e27a1b3e7ce0f274cc7ed750d0e2
                                                       private_key    timestamp
1 5e92ec09501a5d39e251a151f84b5e2228312c445eb23b4e1de6360e27bad54b 1.541204e+12
  submit_status
1             3



$headers
$headers[[1]]
 [1] "HTTP/2 200 "                                                                                                                                                                                                                                            
 [2] "date: Fri, 26 Mar 2021 09:58:13 GMT"                                                                                                                                                                                                                    
 [3] "content-type: application/json;charset=UTF-8"                                                                                                                                                                                                           
 [4] "set-cookie: __cfduid=d9d008c8ab040e9e3e4d30f28b68c197b1616752693; expires=Sun, 25-Apr-21 09:58:13 GMT; path=/; domain=.originstamp.com; HttpOnly; SameSite=Lax"                                                                                         
 [5] "cf-cache-status: DYNAMIC"                                                                                                                                                                                                                               
 [6] "cf-request-id: 090f9167150000dfe3f783d000000001"                                                                                                                                                                                                        
 [7] "expect-ct: max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""                                                                                                                                                   
 [8] "report-to: {\"group\":\"cf-nel\",\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report?s=2pUW93d9AuCcYlam8JZz0l9C5nPYNqhKHRMEwrt2%2BwPn7ZqItjVFeinl2DMGWQpVTAd8U3VSjokj5RaK1mpjPgV%2Bgi1n4XqUE%2B3WeRKG63nh1Pz%2B\"}],\"max_age\":604800}"
 [9] "nel: {\"report_to\":\"cf-nel\",\"max_age\":604800}"                                                                                                                                                                                                     
[10] "server: cloudflare"                                                                                                                                                                                                                                     
[11] "cf-ray: 635f84eb4f57dfe3-FRA"                                                                                                                                                                                                                           
[12] "content-encoding: gzip"                                                                                                                                                                                                                                 
[13] ""                                                                                                                                                                                                                                                       


attr(,"class")
[1] "OriginStampResponse"

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 timestamp

The 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 for or for

To see the downloaded files, click here for the pdf or here for the xml.

References

Ooms, Jeroen. 2020. Openssl: Toolkit for Encryption, Signatures and Certificates Based on OpenSSL. https://CRAN.R-project.org/package=openssl.