Buckets:

download
raw
3.55 kB
#!/usr/bin/env python3
"""Generate obfuscated _build_secrets.py for iOS builds.
Same XOR obfuscation as Android's build.gradle generatePythonSecrets task.
Reads from ~/.<key_name> files and generates the secrets Python module.
Usage:
python3 tools/generate_ios_secrets.py
# Output: apps/ios/Resources/app/ciris_adapters/wallet/providers/_build_secrets.py
"""
import os
from pathlib import Path
# XOR key (same as Android)
XOR_KEY = [0x5A, 0x3C, 0x7E, 0x1F, 0x9B, 0x4D, 0x2E, 0x6A]
# Secrets: function_name -> source_file
SECRETS = {
"arka_api_key": os.path.expanduser("~/.etherspot_android_key"),
"coinbase_paymaster_url": os.path.expanduser("~/.coinbase_paymaster_url"),
}
def obfuscate(value: str) -> list[int]:
return [ord(ch) ^ XOR_KEY[i % len(XOR_KEY)] for i, ch in enumerate(value)]
def main():
obfuscated = {}
for name, filepath in SECRETS.items():
p = Path(filepath)
if p.exists():
value = p.read_text().strip()
obfuscated[name] = obfuscate(value)
print(f" Found: {name} from {filepath}")
else:
obfuscated[name] = []
print(f" WARNING: {filepath} not found — {name} will be empty")
# Generate getter functions
getters = []
for name, data in obfuscated.items():
getters.append(
f'''
def get_{name}() -> str:
"""Get {name} (obfuscated at build time)."""
data = {data}
if not data:
return ""
return _deobfuscate(data, _XK)
'''
)
available = "\n".join(f" - get_{name}()" for name in obfuscated)
# Output MUST be byte-identical to what mobile/androidApp/build.gradle's
# `generatePythonSecrets` task produces — same XOR key, same secrets, same
# docstring, same getter spacing, same trailing newline. Any diff bytes
# here will diverge the SHA-256 from BUILD_SECRETS_HASHES (in
# tools/ops/build_agent_extras.py) and fail runtime integrity checks
# whenever an iOS build's secrets file is hashed against the manifest.
# Three things to keep aligned with the Groovy template:
# 1. Docstring "Generated by mobile/androidApp/build.gradle" — same line
# for both platforms; small white lie keeps the hash deterministic.
# 2. "\n".join(getters) — Groovy's .collect{}.join("\n") produces TWO
# blank lines between getters (each getter starts+ends with \n, plus
# the join \n between them). Don't use "".join here.
# 3. Trailing newline after the joined getters — Groovy's """...""" heredoc
# ends with \n before the closing """; preserve that.
content = f'''"""
Build-time generated secrets - DO NOT EDIT OR COMMIT.
Generated by mobile/androidApp/build.gradle
Available functions:
{available}
"""
from typing import Optional
def _deobfuscate(data: list, key: list) -> str:
"""Deobfuscate XOR-encoded data."""
return ''.join(chr(d ^ key[i % len(key)]) for i, d in enumerate(data))
_XK = [0x5A, 0x3C, 0x7E, 0x1F, 0x9B, 0x4D, 0x2E, 0x6A]
{"\n".join(getters)}
'''
# Write to iOS Resources AND local ciris_adapters
outputs = [
Path("apps/ios/Resources/app/ciris_adapters/wallet/providers/_build_secrets.py"),
Path("ciris_adapters/wallet/providers/_build_secrets.py"),
]
for out in outputs:
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(content)
print(f" Generated: {out}")
print(f"\nDone — {len(obfuscated)} secrets obfuscated")
if __name__ == "__main__":
main()

Xet Storage Details

Size:
3.55 kB
·
Xet hash:
53a7fa812bfff384bef4cc265d5647ea1e7a44faad187882d47668fc127bf6af

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.