vaultix_vxi.pyPythonCopy
# pip install cryptography
import base64, hashlib, re
from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey, X25519PublicKey
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
from cryptography.hazmat.primitives import hashes, serialization
def b64d(s): return base64.urlsafe_b64decode(s + "=" * (-len(s) % 4))
def integration_secret(vxi): # "vxi_…" from App Settings
raw = b64d(vxi[4:])
assert len(raw) == 41 and raw[0] == 1 and hashlib.sha256(b"vaultix-vxi" + raw[:37]).digest()[:4] == raw[37:]
return raw[1:33]
def open_field(vxi, app_id, field, sealed_b64u):
sk = X25519PrivateKey.from_private_bytes(integration_secret(vxi))
pk = sk.public_key().public_bytes(serialization.Encoding.Raw, serialization.PublicFormat.Raw)
sealed = b64d(sealed_b64u); e_pk = sealed[1:33]
ctx = b"udata\x00" + app_id.encode() + b"\x00" + field.encode()
k = HKDF(hashes.SHA256(), 32, e_pk + pk, b"vaultix-zk1-seal\x00" + ctx).derive(
sk.exchange(X25519PublicKey.from_public_bytes(e_pk)))
return AESGCM(k).decrypt(bytes(12), sealed[33:], ctx).decode()
def change_field(name): # field of an audit change value
return name if re.fullmatch(r"[a-z][a-z0-9.\-]{0,63}", name or "") else "change"
vaultixVxi.jsJavaScriptCopy
// Node 18+
const crypto = require('crypto');
const b64d = (s) => Buffer.from(s, 'base64url');
function integrationSecret(vxi) {
const raw = b64d(vxi.slice(4));
const check = crypto.createHash('sha256').update(Buffer.concat([Buffer.from('vaultix-vxi'), raw.subarray(0, 37)])).digest();
if (raw.length !== 41 || raw[0] !== 1 || !check.subarray(0, 4).equals(raw.subarray(37))) throw new Error('invalid vxi_ key');
return raw.subarray(1, 33);
}
const PKCS8 = Buffer.from('302e020100300506032b656e04220420', 'hex');
const SPKI = Buffer.from('302a300506032b656e032100', 'hex');
function openField(vxi, appId, field, sealedB64u) {
const privateKey = crypto.createPrivateKey({ key: Buffer.concat([PKCS8, integrationSecret(vxi)]), format: 'der', type: 'pkcs8' });
const pk = crypto.createPublicKey(privateKey).export({ format: 'der', type: 'spki' }).subarray(-32);
const sealed = b64d(sealedB64u);
const ePk = sealed.subarray(1, 33);
const ctx = Buffer.concat([Buffer.from('udata\0'), Buffer.from(appId), Buffer.from([0]), Buffer.from(field)]);
const shared = crypto.diffieHellman({ privateKey, publicKey: crypto.createPublicKey({ key: Buffer.concat([SPKI, ePk]), format: 'der', type: 'spki' }) });
const key = Buffer.from(crypto.hkdfSync('sha256', shared, Buffer.concat([ePk, pk]), Buffer.concat([Buffer.from('vaultix-zk1-seal\0'), ctx]), 32));
const body = sealed.subarray(33);
const decipher = crypto.createDecipheriv('aes-256-gcm', key, Buffer.alloc(12));
decipher.setAAD(ctx);
decipher.setAuthTag(body.subarray(body.length - 16));
return Buffer.concat([decipher.update(body.subarray(0, body.length - 16)), decipher.final()]).toString('utf8');
}
UsagePythonCopy
# Integration endpoints (connect poll, /integration/connection, connections)
user = resp.json()["user"]
username = open_field(VXI, APP_ID, "username", user["sealed"]["username"])
# Webhooks
event = request.json
app_id = event["app"]["id"]
for field, value in event["data"].get("user", {}).get("sealed", {}).items():
print(field, open_field(VXI, app_id, field, value))
for change in event["data"].get("changes", []):
if (change.get("sealed") or {}).get("new"):
new_value = open_field(VXI, app_id, change_field(change["field"]), change["sealed"]["new"])