README.md
dsnp-identity-assembly
    README.md
    as-pect.config.js
    asconfig.js
    assembly
        __tests__
            as-pect.d.ts
            context.json
            main.spec.ts
        as_types.d.ts
        main.ts
        model.ts
        tsconfig.json
        types.ts
    deployAndIntialize.sh
    package.json
dsnp-identity-ecrecover-experiment
    Cargo.toml
    src
        lib.rs
        sys.rs
    test-verify.sh
dsnp-identity-no-verification
    Cargo.toml
    add_delegate.sh
    build_and_deploy.sh
    minifier.sh
    size_all.sh
    src
        lib.rs
dsnp-identity-with-verification
    Cargo.toml
    add_delegate.sh
    build_and_deploy.sh
    src
        lib.rs
    temp.sh
ed25519_verification
    Cargo.toml
    build_and_deploy.sh
    src
        lib.rs
    verification_test.sh
identity-experiments
    Cargo.toml
    README.md
    src
        lib.rs
modified-linkdrop
    Cargo.toml
    README.md
    build.sh
    src
        lib.rs
registry
    Cargo.toml
    README.md
    build.sh
    src
        lib.rs
        storage_impl.rs
self-upgrade
    Cargo.toml
    README.md
    build.sh
    file-uploader
        index.js
        package-lock.json
        package.json
    src
        lib.rs
sub-account-factory
    Cargo.toml
    README.md
    build.sh
    src
        lib.rs
ui
    README.md
    package.json
    public
        index.html
        manifest.json
        robots.txt
    src
        App.css
        App.js
        App.test.js
        config.js
        index.css
        index.js
        logo.svg
        reportWebVitals.js
        setupTests.js

Indentity example in AssemblyScript
=================================

## Description
# Experimental Repo for NEAR

Testing some ideas around DSNP Identity concepts and how it could work on NEAR.
# NEAR Identity UI

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

NOTE: replace the contract name in config.js with the account ID where the smart contract is deployed.
# NEAR protocol miniature test contract

## Run Tests

```
cargo test -- --nocapture
```

## Compile

```
cargo build --target wasm32-unknown-unknown --release
```

## Deploy to testnet

Login to your own testnet account with `near login` 

```
near deploy --wasmFile target/wasm32-unknown-unknown/release/near_identity.wasm --accountId YOUR_ACCOUNT_HERE
```

## Invoke Methods

```
near call YOUR_ACCOUNT_HERE new_registration --accountId YOUR_ACCOUNT_HERE
```
# Registry contract

Example smart contract to hold registry information (handle, dsnpId, address?)
# Sub-Account Factory

Creates sub-accounts using a counter (starting from 1001).

![Factory diagram](sub_account_factory.png?raw=true "Factory Diagram")

This is directly adapted from **[Sputnikdao-factory2](https://github.com/near-daos/sputnik-dao-contract/tree/main/sputnikdao-factory2)**

## TestNet

```
near dev-deploy --wasmFile=res/sub_account_factory.wasm

# bash
CONTRACT_ID="<generated dev account>"

# Initialize the factory.
near call $CONTRACT_ID new '{}' --accountId $CONTRACT_ID 

# Create a new SubAccount with the given parameters.
near call $CONTRACT_ID create '{"public_key": null}'  --accountId $CONTRACT_ID --amount 30 --gas 100000000000000

# Create a new SubAccount with the given parameters while having Full Access Key to the account (trusted, but useful in case of testing or upgrades)
near call $CONTRACT_ID create '{"public_key": "<public key>"}'  --accountId $CONTRACT_ID --amount 30 --gas 100000000000000

# List all created accounts.
near view $CONTRACT_ID get_accounts_list
```
# Modified LinkDrop contract (Allows creation of top level accounts)

LinkDrop contract allows any user to create a link that their friends can use to claim tokens even if they don't have an account yet.

The way it works:

Sender, that has NEAR:
- Creates a new key pair `(pk1, privkey1)`.
- Calls `linkdrop.send(pk1)` with attached balance of NEAR that they want to send.
- Sends a link to any supported wallet app with `privkey1` as part of URL.

Receiver, that doesn't have NEAR:
- Receives link to the wallet with `privkey1`.
- Wallet creates new key pair for this user (or they generate it via HSM) `(pk2, privkey2)`.
- Enters the `new_account_id` receiver want for their new account.
- Wallet creates a transaction to `linkdrop.create_account_and_claim(new_account_id, pk2)`.
- Contract creates new account with `new_account_id` name and `pk2` as full access key and transfers NEAR that Sender sent.

If Receiver already has account (or Sender wants to get back the money):
- Sign tx with `privkey1` to call `linkdrop.claim()`, which transfers money to signer's account.
# Self upgrading contract

This contract is able to get contract wasm file in a function call and upgrade itself
