AWS Signature V4 request signing, presigned GET/PUT URLs, and S3 / Cloudflare R2 / MinIO bucket & object client.
Pure-Veko AWS Signature Version 4 (AWS4-HMAC-SHA256) object storage client for Amazon S3, Cloudflare R2, MinIO, and Tigris.
cloud_s3 implements the complete AWS Signature Version 4 signing pipeline, presigned URL generation, S3 ListObjectsV2 XML response parsing, and HTTP/1.1 + TLS 1.3 object operations (PUT, GET, byte-range GET, HEAD, DELETE, and ListObjectsV2) in pure Veko with zero external C dependencies.
Key capabilities:
AWS4-HMAC-SHA256): RFC 3986 canonical URI encoding, lexicographically sorted query parameters and lowercase headers, payload SHA-256 hashing, and 4-step HMAC-SHA256 signing key derivation (AWS4 + secret -> date -> region -> s3 -> aws4_request).GET and PUT URLs (UNSIGNED-PAYLOAD) up to 7 days (604800 seconds) for direct browser or CLI uploads and downloads.path_style = true for MinIO, local emulators, and custom R2 endpoints) and virtual-hosted-style addressing (path_style = false for AWS S3 and Tigris)..secret Key Hygiene: derive-signing-key accepts both str and .secret-tainted bytes buffers for in-memory key derivation while keeping wire headers untainted for net/client transport.veko pkg add cloud_s3@1.0.0Import in any .vk module:
use [s3 = cloud_s3]uri-encode, derive-signing-key, sign-headers, presign-url, parse-list-objects-xml) require zero OS capabilities. Live HTTP operations (put-object, get-object, get-object-range, head-object, delete-object, list-objects-v2) require .net (and .clocks when /at is omitted so current UTC time is read via datetime/now-utc).x-amz-content-sha256 over the exact request body bytes, preventing in-transit payload tampering even across proxies..secret taint firewall blocks .secret bytes from crossing network sockets directly. Use derive-signing-key for isolated in-memory key derivation with .secret buffers, and pass untainted credential strings to wire-level put-object/get-object calls confined within your storage adapter module.max_redirects = 0 so signed Authorization headers are never forwarded across cross-host redirects.| Type | Fields | Description |
|---|---|---|
S3Config | endpoint str, region str = 'us-east-1', bucket str, access_key str, path_style bool = true | Endpoint, region, bucket, access key ID, and addressing mode. |
S3ObjectInfo | key str, size i64, etag str, last_modified str = '', storage_class str = 'STANDARD' | Single object entry returned by list-objects-v2. |
ListResult | bucket str, prefix str, key_count i64, is_truncated bool, next_token str, objects block[S3ObjectInfo] | Parsed ListBucketResult (ListObjectsV2) response. |
HeadResult | content_length i64, content_type str, etag str, last_modified str, headers map[str] | Object metadata returned by head-object. |
PutResult | status i64, etag str, version_id str | Upload receipt returned by put-object. |
| Signature | Description |
|---|---|
uri-encode = fn [s str, encode_slash bool] str | Encodes s per AWS SigV4 URI rules (preserves '/' when encode_slash is false). |
format-amz-date = fn [now_unix i64] str | Formats Unix epoch seconds as 'YYYYMMDDTHHMMSSZ'. |
format-date-stamp = fn [now_unix i64] str | Formats Unix epoch seconds as 'YYYYMMDD'. |
payload-hash = fn [payload bytes] str | Returns lowercase hex SHA-256 of payload. |
canonical-query-string = fn [query map[str]] str | URI-encodes and lexicographically sorts query parameters. |
derive-signing-key = fn [secret_key any, date_stamp str, region str, service str] bytes | Derives the 32-byte aws4_request HMAC key (str or bytes). |
resolve-target = fn [cfg S3Config, key str] map[str] | Computes scheme, host_header, canonical_uri, and url_no_query. |
sign-headers = fn [cfg S3Config, secret_key str, method str, canonical_uri str, query map[str], extra_headers map[str], host_header str, payload_sha str, now_unix i64] map[str] | Produces signed HTTP request headers including Authorization. |
presign-url = fn [cfg S3Config, secret_key str, method str, key str, expires_secs i64, now_unix i64] str | Generates a presigned S3 query-authenticated URL. |
parse-list-objects-xml = fn [xml_body str] ListResult | Parses S3 <ListBucketResult> XML into ListResult. |
put-object = fn [cfg S3Config, secret_key str, key str, data bytes, content_type str /at ts i64 = -1] PutResult | Uploads data to key (PUT). |
get-object = fn [cfg S3Config, secret_key str, key str /at ts i64 = -1] bytes | Downloads the complete object at key (GET). |
get-object-range = fn [cfg S3Config, secret_key str, key str, start_byte i64, end_byte i64 /at ts i64 = -1] bytes | Downloads inclusive byte range [start_byte..end_byte] (206 Partial Content). |
head-object = fn [cfg S3Config, secret_key str, key str /at ts i64 = -1] HeadResult | Fetches object metadata without body (HEAD). |
delete-object = fn [cfg S3Config, secret_key str, key str /at ts i64 = -1] bool | Deletes key (DELETE). |
list-objects-v2 = fn [cfg S3Config, secret_key str, prefix str /max-keys max_keys i64 = 1000 /token continuation_token str = '' /at ts i64 = -1] ListResult | Lists objects under prefix via ListObjectsV2. |
use [s3 = cloud_s3]
cfg = s3/S3Config {
endpoint = 'https://acc123.r2.cloudflarestorage.com'
region = 'auto'
bucket = 'veko-builds'
access_key = (os/getenv/or 'S3_ACCESS_KEY' [''])
path_style = true
}
secret = os/getenv/or 'S3_SECRET_KEY' ['']
// Upload an object with error fallback
receipt = s3/put-object/or cfg secret 'releases/v1.0.0/manifest.json' (bytes/from-str '{"ok":true}') 'application/json' [e ->
println `Upload failed: {mold e}`
return e
]
println `Uploaded ETag: {receipt.etag}`
// Read first 64 bytes via HTTP Range
header_slice = s3/get-object-range cfg secret 'releases/v1.0.0/manifest.json' 0 63
// List objects with a prefix
listing = s3/list-objects-v2/max-keys cfg secret 'releases/v1.0.0/' 100
mut i = 0
while i < (len listing.objects) [
obj = listing.objects[i]
println `{obj.key} ({obj.size} bytes)`
i = i + 1
]use [s3 = cloud_s3, dt = datetime]
cfg = s3/S3Config {
endpoint = 'https://s3.us-east-1.amazonaws.com'
region = 'us-east-1'
bucket = 'my-app-uploads'
access_key = 'AKIAEXAMPLE123456789'
path_style = false
}
now_s = dt/to-unix (dt/now-utc)
download_url = s3/presign-url cfg 'my-secret-key' 'GET' 'avatars/user-42.png' 3600 now_s
println download_urlveko check packages/cloud_s3/src/mod.vk
veko check packages/cloud_s3/examples/demo.vk
veko run -C all packages/cloud_s3/examples/demo.vkhttps://veko-lang.org/pkg/cloud_s3/1.0.0.vkp8bd47b7b0bcff7603ea2bbd668e9ab1b172b04ccc5a1cdf516468689987bc7f37b8dd8d94d56b45561b326abdf72d822b28640032a80bfd2ee8d9ed82fc269deed25519:27406074d8681da1d4e6420f5d887cac15c313334c249ac047ba9d4e2df72b70{"name":"cloud_s3","version":"1.0.0","tier":1.0,"tier_label":"Tier 1: Backend Essentials","category":"Cloud Object Storage","description":"AWS Signature V4 request signing, presigned GET/PUT URLs, and S3 / Cloudflare R2 / MinIO bucket & object client.","modules":["cloud_s3"],"homepage":"https://veko-lang.org/packages/cloud_s3"}| Bundle Entry Path | Size | Leaf SHA-256 Digest |
|---|---|---|
| README.md | 7 KB | 3fd29bdd449a7123884ed9ba944a295c1565df5d0974197ead2ae713e68d7b5a |
| examples/demo.vk | 11 KB | b7e24ed7629f83a7c8f180ed48a135b741f6f6a1c105013b920175930f57fdae |
| mod.vk | 19 KB | b76c3866856671372263ed4ee033cdab661f755ffcbbe9897b75ed05be3f2c59 |