Tutorial #3: Managing Records Using Access Records

Access Record Tokens for Testing
For purposes of this tutorial, and only temporarily, the following link will provide a list of Access Record tokens for use: Temporary Access Record Tokens. Note: the keys ar_never and ar_always work as indicated.

1) Create a New Record Using an Access Record

Records may be created per Tutorial #2 with the addition of a query parameter specifying the associated Access Record.

The ar query parameter is needed for creating and updating records with an associated Access Record.

 JavaScript  cURL
const node = 'iv-cos'
const port = 443
const api_root = `https://${ node }.encipher.sk:${ port }`
const params = {
ar: '8f8aa9278592eb3751209c155bd7e4cc3d837d830867c281d8749b2ebbdbe57e'
}
let url = new URL( api_root )

Object.keys( params ).forEach( key => url.searchParams.append( key, params[key] ) )

let formData = new FormData()
formData.append( 'content', 'big ol blob of data' )

fetch(
`${ url }/api/ar/c/`
, {
method: 'POST' // or use PUT when updating existing records
, body: formData
}
)
.then( response => response.json() )
.then( data => console.log( data ) )
curl \
-G -d "ar=8f8aa9278592eb3751209c155bd7e4cc3d837d830867c281d8749b2ebbdbe57e"
-H "Content-Type: application/json" \
-d '{"id": 1234, "content": "some interesting information"}' \
-X POST https://iv-cos.encipher.sk:443/api/ar/c/

If successful, /api/ar/c/ will return with the usual x-hk1 and x-hk2 headers as well as an hk21 JSON array. If supplying the arv flag, then fallback content will be provided.

{
"ok": false,
"err": "AR unlock unauthorized"
}
Save your keys!
Save the hk1 and hk2 keys if you want to keep playing with the same record.

2) Restore a Record Using an Access Record

Use an HTTP GET request with the record's HK1 reference in order to retrieve the record along with an Access Record.

 JavaScript  cURL
const node = 'iv-cos'
const port = 443
const api_root = `https://${ node }.encipher.sk:${ port }`
const hk1 = '12dadd17562a8da5b2ee552dac328553f90f400594a69b840555e5e5f11869a6'
const params = {
ar: '8f8aa9278592eb3751209c155bd7e4cc3d837d830867c281d8749b2ebbdbe57e'
}
let url = new URL( api_root )

Object.keys( params ).forEach( key => url.searchParams.append( key, params[key] ) )

fetch( `${ url }/api/ar/c/${ hk1 }` )
.then( response => { response.blob().then( blob => {
console.log( 'Content-Type:', response.headers.get( 'Content-Type' ) )
console.log( 'Raw data:', blob )
})
})
curl \
-G -d "ar=8f8aa9278592eb3751209c155bd7e4cc3d837d830867c281d8749b2ebbdbe57e" \
https://iv-cos.encipher.sk:443/api/ar/c/12dadd17562a8da5b2ee552dac328553f90f400594a69b840555e5e5f11869a6

3) Update an Existing Record Using an Access Record

Simply follow the directions in step #1 except change the HTTP method to PUT instead of POST in order to patch an existing record. An hk21 key (and corresponding x-hk1 and x-hk2 headers) will be returned if successful. The HK1 reference and HK2 location will be the same when updating an existing record.

Next steps: